import { MigrationInterface, QueryRunner } from "typeorm";

export class LibraryAndSchedulePostEntity1746523729488 implements MigrationInterface {
    name = 'LibraryAndSchedulePostEntity1746523729488'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`CREATE TABLE \`scheduled_post\` (\`id\` int NOT NULL AUTO_INCREMENT, \`alert_id\` int NOT NULL, \`platform\` enum ('facebook', 'twitter', 'instagram', 'linkedin', 'tiktok') NOT NULL, \`content\` text NOT NULL, \`poster_url\` text NULL, \`scheduled_time\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`status\` enum ('pending', 'published', 'failed') NOT NULL DEFAULT 'pending', \`error\` text NULL, \`createdAt\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`updatedAt\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
        await queryRunner.query(`CREATE TABLE \`library\` (\`id\` int NOT NULL AUTO_INCREMENT, \`attachment_url\` varchar(255) NULL, \`attachment_name\` varchar(255) NULL, \`attachment_type\` varchar(255) NULL, \`attachment_size\` varchar(255) NULL, \`attachment_description\` varchar(255) NULL, \`attachment_category\` varchar(255) NULL, \`is_public\` tinyint NOT NULL DEFAULT 0, \`tags\` text NULL, \`is_active\` tinyint NOT NULL DEFAULT 1, \`created_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`updated_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`attachment_posted_by\` int NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
        await queryRunner.query(`ALTER TABLE \`library\` ADD CONSTRAINT \`FK_6020a60ca4d6f4dc3ecd545a3cd\` FOREIGN KEY (\`attachment_posted_by\`) REFERENCES \`users\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE \`library\` DROP FOREIGN KEY \`FK_6020a60ca4d6f4dc3ecd545a3cd\``);
        await queryRunner.query(`DROP TABLE \`library\``);
        await queryRunner.query(`DROP TABLE \`scheduled_post\``);
    }

}
