import pool from './db.js';

async function createTable() {
    try {
        await pool.query(`
            CREATE TABLE IF NOT EXISTS documents (
                id VARCHAR(36) PRIMARY KEY,
                project_id VARCHAR(36),
                name VARCHAR(255) NOT NULL,
                type VARCHAR(100),
                url VARCHAR(500) NOT NULL,
                size INT,
                created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE SET NULL
            );
        `);
        console.log('Documents table created successfully');
        process.exit(0);
    } catch (error) {
        console.error('Error creating table:', error);
        process.exit(1);
    }
}

createTable();
