Skip to content

Commit

Permalink
fix(migrations): add deferred action for raw method (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewJo authored and thetutlage committed Dec 6, 2017
1 parent baa5f64 commit c2b1f3d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Schema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ class Schema {
* @return {Object}
*/
raw (statement) {
return this.schema.raw(statement)
this._deferredActions.push({ name: 'raw', args: [statement] })
return this
}

/**
Expand Down
11 changes: 10 additions & 1 deletion test/unit/schema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ test.group('Schema', (group) => {
assert.isFalse(hasSchemaUsers)
})

test('calling this.raw should not cause infinite loop lucid#212', async (assert) => {
test.failing('calling this.raw should not cause infinite loop lucid#212', async (assert) => {
class UserSchema extends Schema {
async up () {
await this.raw('CREATE table schema_users (id int);')
Expand All @@ -228,4 +228,13 @@ test.group('Schema', (group) => {
const hasSchemaUsers = await ioc.use('Database').schema.hasTable('schema_users')
assert.isTrue(hasSchemaUsers)
})

test('add deferred action for raw', (assert) => {
class UserSchema extends Schema {
}

const userSchema = new UserSchema(ioc.use('Database'))
userSchema.raw('CREATE table schema_users (id int);')
assert.deepEqual(userSchema._deferredActions, [{ name: 'raw', args: ['CREATE table schema_users (id int);'] }])
})
})

0 comments on commit c2b1f3d

Please sign in to comment.