/
WithView.ts
28 lines (24 loc) · 1.15 KB
/
WithView.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { MigrationInterface, QueryRunner } from "../../../../src";
export class WithView1623518107000 implements MigrationInterface {
name = "WithView1623518107000";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
"CREATE TABLE `foo` (`id` int NOT NULL AUTO_INCREMENT, `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB"
);
await queryRunner.query(
"CREATE VIEW `foo_view` AS SELECT updated_at FROM `foo`"
);
await queryRunner.query(
"INSERT INTO `typeorm_metadata`(`type`, `schema`, `name`, `value`) VALUES (?, ?, ?, ?)",
["VIEW", null, "foo_view", "SELECT `updated_at` FROM `foo`"]
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
"DELETE FROM `typeorm_metadata` WHERE `type` = 'VIEW' AND `schema` = ? AND `name` = ?",
[null, "foo_view"]
);
await queryRunner.query("DROP VIEW `foo_view`");
await queryRunner.query("DROP Table `foo`");
}
}