this.raw is broken after update to 4.x?
~~↓↓↓ See update & the fix on the bottom ↓↓↓~~
Before migration to adonis/lucid 4.x I had a few raw migrations like:
const Schema = use('Schema')
class WhateverMigration extends Schema {
up() {
this.raw("WHATEVER COMMAND")
}
down() {
// My down code
}
}
module.exports = WhateverMigration
These raw migrations worked just fine with Adonis/Lucid 3.x, however, these do not pass with adonis 4.x and give following trace:
at WhateverMigration.raw (/path_to_project/node_modules/@adonisjs/lucid/src/Schema/index.js:238:17)
at WhateverMigration.raw (/path_to_project/node_modules/@adonisjs/lucid/src/Schema/index.js:238:17)
at WhateverMigration.raw (/path_to_project/node_modules/@adonisjs/lucid/src/Schema/index.js:238:17)
at WhateverMigration.raw (/path_to_project/node_modules/@adonisjs/lucid/src/Schema/index.js:238:17)
at WhateverMigration.raw (/path_to_project/node_modules/@adonisjs/lucid/src/Schema/index.js:238:17)
at WhateverMigration.raw (/path_to_project/node_modules/@adonisjs/lucid/src/Schema/index.js:238:17)
at WhateverMigration.raw (/path_to_project/node_modules/@adonisjs/lucid/src/Schema/index.js:238:17)
at WhateverMigration.up (/path_to_project/database/migrations/1493454741900_add-superadmin-users.js:8:10)
at Migration._executeSchema (/path_to_project/node_modules/@adonisjs/lucid/src/Migration/index.js:250:36)
at Migration._execute (/path_to_project/node_modules/@adonisjs/lucid/src/Migration/index.js:270:18)
at Migration.up (/path_to_project/node_modules/@adonisjs/lucid/src/Migration/index.js:362:18)
at <anonymous>
I have to admit that line
at WhateverMigration.raw (/path_to_project/node_modules/@adonisjs/lucid/src/Schema/index.js:238:17)
Is repeated around 10000+ times like it goes to some kind of infinite loop.
The code in raw statement does not matter, I tried to put even very simple things — they all fail. I have a few dozen migration files so I'm quite sure that only raw is failing, all the other commands like table.create work fine.
Update
~~Changing this.raw("WHATEVER COMMAND") to this.schema.raw("WHATEVER COMMAND") seems to fix the issue.~~ No, apparently, in this case the code is simply not run
So I thought that changing this.raw("WHATEVER COMMAND") to this.schema.raw("WHATEVER COMMAND" fixes the issue. But apparently, it does not run the code in this case. So the issue is still open for me…
I'm believe I'm having the same issue. Looking at the code should this be using the _deferredActions array?
raw (statement) {
this.deferredActions.push({ name: 'raw', args: [statement] })
return this
}
Have you have tried
async up () {
await this.schema.raw("")
}
Also fixed this.raw. Following should work fine
async up () {
await this.raw("")
}