-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-db.mjs
More file actions
58 lines (52 loc) · 1.71 KB
/
Copy pathinit-db.mjs
File metadata and controls
58 lines (52 loc) · 1.71 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pkg from "pg";
const { Pool } = pkg;
import dotenv from "dotenv";
dotenv.config();
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
async function initDb() {
try {
console.log("Connecting to Postgres...");
await pool.query(`
CREATE TABLE IF NOT EXISTS users (
id VARCHAR(255) PRIMARY KEY,
email VARCHAR(255),
display_name VARCHAR(255),
photo_url TEXT,
storage_used BIGINT DEFAULT 0,
total_storage BIGINT DEFAULT 5368709120,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS files (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
name VARCHAR(255) NOT NULL,
type VARCHAR(100) NOT NULL,
size BIGINT NOT NULL,
owner_id VARCHAR(255) REFERENCES users(id),
parent_id VARCHAR(255) DEFAULT 'root',
s3_key TEXT NOT NULL,
is_shared BOOLEAN DEFAULT false,
is_starred BOOLEAN DEFAULT false,
is_deleted BOOLEAN DEFAULT false,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS transactions (
transaction_id VARCHAR(255) PRIMARY KEY,
user_id VARCHAR(255) REFERENCES users(id),
amount BIGINT NOT NULL,
status VARCHAR(50) DEFAULT 'PENDING',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
`);
console.log("Database initialized successfully.");
} catch (err) {
console.error("Failed to initialize database:", err);
} finally {
pool.end();
}
}
initDb();