feat: add scripts to create participants and users tables in the database

This commit is contained in:
2026-02-22 09:37:31 +05:30
parent 19f2e71baf
commit bd650a8276
2 changed files with 77 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
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) DEFAULT 'audience' NOT NULL
);
`;
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();