Skip to content

Commit

Permalink
fix(migrations): expose knex.schema via this.schema
Browse files Browse the repository at this point in the history
all migrations schemas now can access knex.schema via this.schema
  • Loading branch information
thetutlage committed Jul 16, 2017
1 parent f58c986 commit 5a93394
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Migrations/Mixins/Migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Migrate._schemaCallback = function (callback) {
*/
Migrate._decorateSchema = function (schemaInstance) {
schemaInstance.fn = this.database.fn
schemaInstance.schema = this.database.schema
}

/**
Expand Down
18 changes: 18 additions & 0 deletions test/unit/migrations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,22 @@ describe('Migrations', function () {
expect(accountsTable).deep.equal({})
yield runner.database.schema.dropTable('adonis_migrations')
})

it('should have access to knex schema inside the schema class', function * () {
const Runner = new Migrations(Database, Config)
const runner = new Runner()
let schema = null
class Users extends Schema {
up () {
this.table('users', (table) => {
schema = this.schema
})
}
}
const migrations = {'2015-01-20': Users}
yield runner.up(migrations)
expect(schema).to.be.an('object')
expect(schema.raw).to.be.a('function')
yield runner.database.schema.dropTable('adonis_migrations')
})
})

0 comments on commit 5a93394

Please sign in to comment.