const { Pool } = require('pg'); require('dotenv').config(); const createTableQuery = ` CREATE TABLE IF NOT EXISTS artworks ( id SERIAL PRIMARY KEY, participant_id INT NOT NULL REFERENCES participants(id) ON DELETE CASCADE, category VARCHAR(50) NOT NULL CHECK (category IN ('digital', 'handdrawn', 'poster')), image_url TEXT NOT NULL, title VARCHAR(255) NOT NULL, created_at TIMESTAMP DEFAULT NOW(), CONSTRAINT unique_participant_category UNIQUE (participant_id, category) ); `; async function createTable() { const pool = new Pool({ connectionString: process.env.DATABASE_URL, }); try { console.log('Connecting to the database...'); const client = await pool.connect(); console.log('Creating artworks table if it does not exist...'); await client.query(createTableQuery); console.log('Artworks table created or already exists.'); client.release(); } catch (error) { console.error('Error creating artworks table:', error); } finally { await pool.end(); } } createTable();