import { MigrationInterface, QueryRunner } from 'typeorm';

export class importedIds1714690838998 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
            CREATE TABLE asset_imports(
                project_id BIGINT NOT NULL REFERENCES projects(id) ON UPDATE CASCADE ON DELETE CASCADE,
                imported_id UUID NOT NULL,
                new_id UUID NOT NULL,
                PRIMARY KEY(project_id, imported_id, new_id),
                FOREIGN KEY(project_id, new_id) references assets(project_id, id) ON UPDATE CASCADE ON DELETE CASCADE
            )        
        `);
    await queryRunner.query(`
            CREATE TABLE workspace_imports(
                project_id BIGINT NOT NULL REFERENCES projects(id) ON UPDATE CASCADE ON DELETE CASCADE,
                imported_id UUID NOT NULL,
                new_id UUID NOT NULL,
                PRIMARY KEY(project_id, imported_id, new_id),
                FOREIGN KEY(project_id, new_id) references workspaces(project_id, id) ON UPDATE CASCADE ON DELETE CASCADE
            )        
        `);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
            DROP TABLE asset_imports
        `);
    await queryRunner.query(`
            DROP TABLE workspace_imports
        `);
  }
}
