import { query } from '../mysql';

async function createSchema() {
  try {
    console.log('Creating tables...');

    await query(`
      CREATE TABLE IF NOT EXISTS video (
        id INT AUTO_INCREMENT PRIMARY KEY,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
        genre VARCHAR(255),
        sub_genre VARCHAR(255),
        scene TEXT,
        action TEXT,
        camera TEXT,
        image_prompt TEXT,
        video_prompt TEXT,
        image_path VARCHAR(255),
        video_path VARCHAR(255)
      )
    `);

    await query(`
      CREATE TABLE IF NOT EXISTS tag (
        id INT AUTO_INCREMENT PRIMARY KEY,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
        tag VARCHAR(255) UNIQUE
      )
    `);

    await query(`
      CREATE TABLE IF NOT EXISTS tag_video (
        id INT AUTO_INCREMENT PRIMARY KEY,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
        tag_id INT,
        video_id INT,
        FOREIGN KEY (tag_id) REFERENCES tag(id),
        FOREIGN KEY (video_id) REFERENCES video(id)
      )
    `);

    console.log('Tables created successfully.');
  } catch (error) {
    console.error('Error creating tables:', error);
  } finally {
    process.exit();
  }
}

createSchema();
