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

Migration fail with multiple create tables in one migration #29

Closed
ntvsx193 opened this issue May 19, 2016 · 4 comments
Closed

Migration fail with multiple create tables in one migration #29

ntvsx193 opened this issue May 19, 2016 · 4 comments
Assignees

Comments

@ntvsx193
Copy link
Contributor

ntvsx193 commented May 19, 2016

/database/migrations/1463581000000_init.js

'use strict'

const Schema = use('Schema')

class InitSchema extends Schema {

  up () {
    this.create('users', function (table) {
      table.increments('id')
      table.string('email').unique().notNullable()
      table.string('password').notNullable()
      table.timestamp('activated_at').index()
      table.timestamps()
    })

    this.create('accounts', function (table) {
      table.increments('id')
      table.timestamps()
    })
  }

  // inverse order for drop!
  down () {
    this.drop('accounts')
    this.drop('users')
  }

}

module.exports = InitSchema

Then run migration (used PostgreSQL)

vagrant@vm:/vagrant$ DEBUG=knex:query node ace migration:run
  knex:query create table if not exists "adonis_schema" ("id" serial primary key, "name" varchar(255), "batch" integer, "migration_time" timestamptz) +0ms
  knex:query select "name", "name" from "adonis_schema" +8ms
  knex:query create table if not exists "adonis_schema_lock" ("id" serial primary key, "is_locked" boolean) +6ms
  knex:query select * from "adonis_schema_lock" where "is_locked" = ? order by "id" desc limit ? +7ms
  knex:query insert into "adonis_schema_lock" ("is_locked") values (?) +6ms
  knex:query create table "users" ("id" serial primary key, "email" varchar(255) not null, "password" varchar(255) not null, "activated_at" timestamptz, "created_at" timestamptz, "updated_at" timestamptz) +7ms
  knex:query alter table "users" add constraint users_email_unique unique ("email") +6ms
  knex:query create index users_activated_at_index on "users" ("activated_at") +2ms
  knex:query create table "accounts" ("id" serial primary key, "created_at" timestamptz, "updated_at" timestamptz) +3ms
  knex:query create table "users" ("id" serial primary key, "email" varchar(255) not null, "password" varchar(255) not null, "activated_at" timestamptz, "created_at" timestamptz, "updated_at" timestamptz) +9ms
  knex:query drop table "adonis_schema_lock" +5ms
error: create table "users" ("id" serial primary key, "email" varchar(255) not null, "password" varchar(255) not null, "activated_at" timestamptz, "created_at" timestamptz, "updated_at" timestamptz) - relation "users" already exists

Dependency in package.json:

...
"adonis-lucid": "git+https://github.com/adonisjs/adonis-lucid.git#feature-version-3",
@RomainLanz
Copy link
Member

RomainLanz commented May 20, 2016

Did you have others migrations?

@ntvsx193
Copy link
Contributor Author

No, only one migration.
It happens only if create table > 1 in migration.
i.e. i have 2 migrations, all well good..
/database/migrations/1463581000000_create_users_table.js

'use strict'

const Schema = use('Schema')

class CreateUsersTableSchema extends Schema {

  up () {
    this.create('users', function (table) {
      table.increments('id')
      table.string('email').unique().notNullable()
      table.string('password').notNullable()
      table.timestamp('activated_at').index()
      table.timestamps()
    })
  }

  // inverse order for drop!
  down () {
    this.drop('users')
  }

}

module.exports = CreateUsersTableSchema

/database/migrations/1463581000001_create_accounts_table.js

'use strict'

const Schema = use('Schema')

class CreateAccountsTableSchema extends Schema {

  up () {
    this.create('accounts', function (table) {
      table.increments('id')
      table.timestamps()
    })
  }

  // inverse order for drop!
  down () {
    this.drop('accounts')
  }

}

module.exports = CreateAccountsTableSchema

@thetutlage thetutlage self-assigned this May 20, 2016
@thetutlage
Copy link
Member

@ntvsx193 Identified bug, will fix it.

@thetutlage
Copy link
Member

Fixed and will be part of 3.0 release

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