init commit
This commit is contained in:
27
server/db.js
Normal file
27
server/db.js
Normal file
@@ -0,0 +1,27 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user