Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rerun ace migration run with oracledb throws error #172

Closed
3dd13 opened this issue Sep 1, 2017 · 2 comments
Closed

Rerun ace migration run with oracledb throws error #172

3dd13 opened this issue Sep 1, 2017 · 2 comments

Comments

@3dd13
Copy link

3dd13 commented Sep 1, 2017

Error

it happens in both version 3.0.16 and 4, with Oracle.
when you run ./ace migration:run more than once, following errors shown:

Error: DECLARE PK_NAME VARCHAR(200); BEGIN EXECUTE IMMEDIATE ('CREATE SEQUENCE "adonis_schema_seq"'); SELECT cols.column_name INTO PK_NAME FROM all_constraints cons, all_cons_columns cols WHERE cons.constraint_type = 'P' AND cons.constraint_name = cols.constraint_name AND cons.owner = cols.owner AND cols.table_name = 'adonis_schema'; execute immediate ('create or replace trigger "adonis_schema_autoinc_trg" BEFORE INSERT on "adonis_schema" for each row declare checking number := 1; begin if (:new."' || PK_NAME || '" is null) then while checking >= 1 loop select "adonis_schema_seq".nextval into :new."' || PK_NAME || '" from dual; select count("' || PK_NAME || '") into checking from "adonis_schema" where "' || PK_NAME || '" = :new."' || PK_NAME || '"; end loop; end if; end;'); END; - ORA-00955: name is already used by an existing object ORA-06512: at line 1

More Info

it is actually because knex #createTableIfNotExists is actually trying to create sequence even if the table exist already.
the contributors are still discussing, some said it is the indented behaviour, some said no:
knex/knex#1303

Proposed fix / change

change https://github.com/adonisjs/adonis-lucid/blob/develop/src/Migration/index.js#L46 to use hasTable and createTable separately. For example:

  const migrationTableAlreadyExist = yield this.database.schema.hasTable(this.migrationsTable)
  if (!migrationTableAlreadyExist) {
    return this.database.schema.createTable(this.migrationsTable, function (table) {
      table.increments('id')
      table.string('name')
      table.integer('batch')
      table.timestamp('migration_time')
    })
  }
@thetutlage
Copy link
Member

Lemme look into it

@rohhamh
Copy link

rohhamh commented Sep 12, 2022

is it fixed yet?
in my case it's occurring after having dropped the lock table
using version 0.20.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants