I'm trying to create a migration with typeorm. Here's my file:
import { MigrationInterface, QueryRunner } from "typeorm"
export class changeAddressNumberDatatype1654614315001 implements MigrationInterface {
async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "accounts" MODIFY "address_number" varchar(50)`,
`ALTER TABLE "service-request" MODIFY "address_number" varchar(50)`
)
}
async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "accounts" MODIFY "address_number" int`,
`ALTER TABLE "service-request" MODIFY "address_number" int`
)
}
}
The error I get is:
src/migration/1654614315001-changeAddressNumberDatatype.ts:7:13 - error TS2345: Argument of type 'string' is not assignable to parameter of type 'any[]'.
If I modify only one table at a time it doesn't give me any errors. Is that the way to do it? Or can I modify multiple tables on the same migration?
There is no way to modify columns of multiple tables with the method query
.
The correct way to do what you want it's doing the modify it one by one:
export class changeAddressNumberDatatype1654614315001
implements MigrationInterface
{
async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "accounts" MODIFY "address_number" varchar(50)`,
);
await queryRunner.query(
`ALTER TABLE "service-request" MODIFY "address_number" varchar(50)`,
);
}
async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "accounts" MODIFY "address_number" int`,
);
await queryRunner.query(
`ALTER TABLE "service-request" MODIFY "address_number" int`,
);
}
}
if you don't want to use a string for this you could use the method changeColumn
or changeColumns
from multiple columns of the same table.