feat(web): T-WEB-002 TypeORM 迁移生成表结构(5 表,可逆)
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class InitSchema1789382903060 implements MigrationInterface {
|
||||
name = 'InitSchema1789382903060'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`CREATE TABLE \`assets\` (\`id\` bigint NOT NULL AUTO_INCREMENT, \`kind\` varchar(32) NOT NULL, \`original_name\` varchar(255) NOT NULL, \`stored_path\` varchar(500) NOT NULL, \`mime\` varchar(128) NOT NULL DEFAULT 'application/octet-stream', \`size\` bigint NOT NULL, \`sha256\` char(64) NOT NULL, \`created_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), INDEX \`idx_assets_kind\` (\`kind\`), UNIQUE INDEX \`idx_assets_sha256\` (\`sha256\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||
await queryRunner.query(`CREATE TABLE \`models\` (\`id\` bigint NOT NULL AUTO_INCREMENT, \`name\` varchar(200) NOT NULL, \`format\` varchar(16) NOT NULL, \`vrm_version\` varchar(16) NULL, \`is_primary\` tinyint(1) NOT NULL DEFAULT '0', \`file_asset_id\` bigint NULL, \`thumbnail_asset_id\` bigint NULL, \`source_type\` varchar(32) NOT NULL, \`source_name\` varchar(200) NOT NULL, \`source_url\` varchar(500) NOT NULL, \`license\` varchar(100) NOT NULL, \`author\` varchar(200) NOT NULL, \`status\` varchar(16) NOT NULL DEFAULT 'draft', \`created_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`updated_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`deleted_at\` datetime(6) NULL, INDEX \`idx_models_is_primary\` (\`is_primary\`), INDEX \`idx_models_format\` (\`format\`), INDEX \`idx_models_status\` (\`status\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||
await queryRunner.query(`CREATE TABLE \`songs\` (\`id\` bigint NOT NULL AUTO_INCREMENT, \`title\` varchar(200) NOT NULL, \`artist\` varchar(200) NOT NULL, \`album\` varchar(200) NULL, \`language\` varchar(32) NULL, \`duration_ms\` int NULL, \`bpm\` decimal(7,2) NULL, \`difficulty\` tinyint NULL, \`tags\` text NULL, \`cover_asset_id\` bigint NULL, \`audio_asset_id\` bigint NULL, \`source_type\` varchar(32) NOT NULL, \`source_name\` varchar(200) NOT NULL, \`source_url\` varchar(500) NOT NULL, \`license\` varchar(100) NOT NULL, \`author\` varchar(200) NOT NULL, \`status\` varchar(16) NOT NULL DEFAULT 'draft', \`created_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`updated_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`deleted_at\` datetime(6) NULL, INDEX \`idx_songs_status\` (\`status\`), INDEX \`idx_songs_artist\` (\`artist\`), INDEX \`idx_songs_title\` (\`title\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||
await queryRunner.query(`CREATE TABLE \`motions\` (\`id\` bigint NOT NULL AUTO_INCREMENT, \`song_id\` bigint NULL, \`name\` varchar(200) NOT NULL, \`format\` varchar(24) NOT NULL, \`file_asset_id\` bigint NULL, \`fps\` decimal(8,3) NULL, \`frame_count\` int NULL, \`duration_ms\` int NULL, \`keypoint_format\` varchar(32) NULL, \`keypoint_asset_id\` bigint NULL, \`keypoint_frames\` int NULL, \`preprocess_state\` varchar(16) NOT NULL DEFAULT 'none', \`preprocess_error\` text NULL, \`source_type\` varchar(32) NOT NULL, \`source_name\` varchar(200) NOT NULL, \`source_url\` varchar(500) NOT NULL, \`license\` varchar(100) NOT NULL, \`author\` varchar(200) NOT NULL, \`status\` varchar(16) NOT NULL DEFAULT 'draft', \`created_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`updated_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`deleted_at\` datetime(6) NULL, INDEX \`idx_motions_format\` (\`format\`), INDEX \`idx_motions_status\` (\`status\`), INDEX \`idx_motions_song_id\` (\`song_id\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||
await queryRunner.query(`CREATE TABLE \`review_records\` (\`id\` bigint NOT NULL AUTO_INCREMENT, \`target_type\` varchar(16) NOT NULL, \`target_id\` bigint NOT NULL, \`action\` varchar(16) NOT NULL, \`from_status\` varchar(16) NOT NULL, \`to_status\` varchar(16) NOT NULL, \`reviewer\` varchar(100) NULL, \`comment\` text NULL, \`created_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), INDEX \`idx_review_created_at\` (\`created_at\`), INDEX \`idx_review_target\` (\`target_type\`, \`target_id\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||
await queryRunner.query(`ALTER TABLE \`motions\` ADD CONSTRAINT \`FK_7db5ad6652cd475d5e7274fdb01\` FOREIGN KEY (\`song_id\`) REFERENCES \`songs\`(\`id\`) ON DELETE SET NULL ON UPDATE NO ACTION`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`motions\` DROP FOREIGN KEY \`FK_7db5ad6652cd475d5e7274fdb01\``);
|
||||
await queryRunner.query(`DROP INDEX \`idx_review_target\` ON \`review_records\``);
|
||||
await queryRunner.query(`DROP INDEX \`idx_review_created_at\` ON \`review_records\``);
|
||||
await queryRunner.query(`DROP TABLE \`review_records\``);
|
||||
await queryRunner.query(`DROP INDEX \`idx_motions_song_id\` ON \`motions\``);
|
||||
await queryRunner.query(`DROP INDEX \`idx_motions_status\` ON \`motions\``);
|
||||
await queryRunner.query(`DROP INDEX \`idx_motions_format\` ON \`motions\``);
|
||||
await queryRunner.query(`DROP TABLE \`motions\``);
|
||||
await queryRunner.query(`DROP INDEX \`idx_songs_title\` ON \`songs\``);
|
||||
await queryRunner.query(`DROP INDEX \`idx_songs_artist\` ON \`songs\``);
|
||||
await queryRunner.query(`DROP INDEX \`idx_songs_status\` ON \`songs\``);
|
||||
await queryRunner.query(`DROP TABLE \`songs\``);
|
||||
await queryRunner.query(`DROP INDEX \`idx_models_status\` ON \`models\``);
|
||||
await queryRunner.query(`DROP INDEX \`idx_models_format\` ON \`models\``);
|
||||
await queryRunner.query(`DROP INDEX \`idx_models_is_primary\` ON \`models\``);
|
||||
await queryRunner.query(`DROP TABLE \`models\``);
|
||||
await queryRunner.query(`DROP INDEX \`idx_assets_sha256\` ON \`assets\``);
|
||||
await queryRunner.query(`DROP INDEX \`idx_assets_kind\` ON \`assets\``);
|
||||
await queryRunner.query(`DROP TABLE \`assets\``);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user