Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore migrate options for typeorm running #2590

Merged
merged 1 commit into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/typeorm/src/dataSourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export class TypeORMDataSourceManager extends DataSourceManager<DataSource> {
config: any,
dataSourceName: string
): Promise<DataSource> {
if (config['migrations']) {
delete config['migrations'];
}
const dataSource = new DataSource(config);
await dataSource.initialize();
return dataSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export default (appInfo) => {
database: join(__dirname, '../../test.sqlite'),
logging: true,
entities: [Message, User, OriginUser],
subscribers: [EverythingSubscriber]
subscribers: [EverythingSubscriber],
migrations: [
'*/migration/*.ts'
],
}
},
defaultDataSourceName: 'default',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class user1671508484455 implements MigrationInterface {
name = 'user1671508484455'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "temporary_photo" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "newName" varchar(100) NOT NULL, "description" text NOT NULL, "filename" varchar NOT NULL, "views" double NOT NULL, "isPublished" boolean NOT NULL)`);
await queryRunner.query(`INSERT INTO "temporary_photo"("id", "newName", "description", "filename", "views", "isPublished") SELECT "id", "name", "description", "filename", "views", "isPublished" FROM "photo"`);
await queryRunner.query(`DROP TABLE "photo"`);
await queryRunner.query(`ALTER TABLE "temporary_photo" RENAME TO "photo"`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "photo" RENAME TO "temporary_photo"`);
await queryRunner.query(`CREATE TABLE "photo" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(100) NOT NULL, "description" text NOT NULL, "filename" varchar NOT NULL, "views" double NOT NULL, "isPublished" boolean NOT NULL)`);
await queryRunner.query(`INSERT INTO "photo"("id", "name", "description", "filename", "views", "isPublished") SELECT "id", "newName", "description", "filename", "views", "isPublished" FROM "temporary_photo"`);
await queryRunner.query(`DROP TABLE "temporary_photo"`);
}

}