feat: add scripts to create participants and users tables in the database
This commit is contained in:
43
scripts/create_participant_table.js
Normal file
43
scripts/create_participant_table.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const { Pool } = require('pg');
|
||||
require('dotenv').config();
|
||||
|
||||
const createTableQuery = `
|
||||
CREATE TABLE IF NOT EXISTS participants (
|
||||
id SERIAL PRIMARY KEY,
|
||||
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
participant_name VARCHAR(255) NOT NULL,
|
||||
email VARCHAR(255) NOT NULL,
|
||||
year INTEGER NOT NULL,
|
||||
phone_number VARCHAR(15),
|
||||
is_digital_art BOOLEAN DEFAULT false,
|
||||
digital_art_link TEXT DEFAULT NULL,
|
||||
is_handdrawn BOOLEAN DEFAULT false,
|
||||
handdrawn_link TEXT DEFAULT NULL,
|
||||
is_poster BOOLEAN DEFAULT false,
|
||||
poster_link TEXT DEFAULT NULL,
|
||||
CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
`;
|
||||
|
||||
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 participants table if it does not exist...');
|
||||
await client.query(createTableQuery);
|
||||
|
||||
console.log('Participants table created or already exists.');
|
||||
client.release();
|
||||
} catch (error) {
|
||||
console.error('Error creating participants table:', error);
|
||||
} finally {
|
||||
await pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
createTable();
|
||||
34
scripts/create_users_table.js
Normal file
34
scripts/create_users_table.js
Normal 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();
|
||||
Reference in New Issue
Block a user