28 lines
629 B
JavaScript
28 lines
629 B
JavaScript
const { Pool } = require('pg');
|
|
require('dotenv').config();
|
|
|
|
const pool = new Pool({
|
|
connectionString: process.env.DATABASE_URL
|
|
});
|
|
|
|
const initDb = async () => {
|
|
try {
|
|
await pool.query(`
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
id SERIAL PRIMARY KEY,
|
|
username VARCHAR(50) UNIQUE NOT NULL,
|
|
email VARCHAR(255) UNIQUE NOT NULL,
|
|
password_hash VARCHAR(255) NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
)
|
|
`);
|
|
console.log('Database initialized');
|
|
} catch (err) {
|
|
console.error('Error initializing database', err);
|
|
}
|
|
};
|
|
|
|
initDb();
|
|
|
|
module.exports = pool;
|