-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-db.js
More file actions
33 lines (28 loc) · 936 Bytes
/
setup-db.js
File metadata and controls
33 lines (28 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const { Client } = require('pg');
// Connect to the Postgres Container
const client = new Client({
connectionString: 'postgres://admin:password123@localhost:5432/flashflow'
});
async function createTables() {
try {
await client.connect();
console.log('🔌 Connected to Postgres');
// 1. Create Orders Table
await client.query(`
CREATE TABLE IF NOT EXISTS orders (
id SERIAL PRIMARY KEY,
user_id VARCHAR(50) NOT NULL,
item VARCHAR(100) NOT NULL,
price DECIMAL(10, 2) NOT NULL,
status VARCHAR(20) DEFAULT 'SUCCESS',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
`);
console.log('✅ Tables Created Successfully!');
} catch (err) {
console.error('❌ Error:', err);
} finally {
await client.end();
}
}
createTables();