diff --git a/src/Schema/index.js b/src/Schema/index.js index 895efc15..2b5d25e8 100644 --- a/src/Schema/index.js +++ b/src/Schema/index.js @@ -235,7 +235,8 @@ class Schema { * @return {Object} */ raw (statement) { - return this.schema.raw(statement) + this._deferredActions.push({ name: 'raw', args: [statement] }) + return this } /** diff --git a/test/unit/schema.spec.js b/test/unit/schema.spec.js index f75615c9..0fe94e3f 100644 --- a/test/unit/schema.spec.js +++ b/test/unit/schema.spec.js @@ -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);') @@ -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);'] }]) + }) })