-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Description
Issue type:
[ ] question
[ ] bug report
[x] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
[x] any
TypeORM version:
[ ] latest
[x] @next
[ ] 0.x.x
(or put your version here)
Request:
Actually when we migrate we mostly use queryRunner.query
which run raw SQL queries. But it would be awesome to be able to use decorators instead. Then a migration can be even more readable and it's code will become compliant with it's model.
Here's an example:
We add an index to a table, then just do
Actual way to migrate:
class addIndexToTable123456789 {
up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_1234" ON "schema"."table" ("col1", "col2", "col3") `)
}
down(): Promise<void> {
await queryRunner.query(`DROP INDEX "schema"."IDX_1234"`)
}
}
Requested changes:
@migrate
class addIndexToTable123456789 {
@up()
@addIndex('indexName', 'tableName', ['col1', 'col2', 'col3'], { unique: true })
@down()
@dropIndex('indexName', 'tableName')
}
The main goal is avoiding raw strings and use a minimalist code to perform migrations when it's possible, when we can't we can still use queryRunner
.