Files
ArtSplash/scripts/create_users_table.js
2026-02-22 10:18:15 +05:30

35 lines
968 B
JavaScript

const { Pool } = require('pg');
require('dotenv').config();
const createTableQuery = `
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
name VARCHAR(255),
user_type VARCHAR(50) NOT NULL DEFAULT 'audience' CHECK (user_type IN ('audience', 'participant', 'admin', 'moderator')),
created_at TIMESTAMP DEFAULT NOW()
);
`;
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 users table if it does not exist...');
await client.query(createTableQuery);
console.log('Users table created or already exists.');
client.release();
} catch (error) {
console.error('Error creating users table:', error);
} finally {
await pool.end();
}
}
createTable();