pwa ops
This commit is contained in:
37
server/db.js
37
server/db.js
@@ -7,6 +7,7 @@ const pool = new Pool({
|
||||
|
||||
const initDb = async () => {
|
||||
try {
|
||||
// 1. Users table
|
||||
await pool.query(`
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
@@ -16,6 +17,42 @@ const initDb = async () => {
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
`);
|
||||
|
||||
// 2. Beans table
|
||||
await pool.query(`
|
||||
CREATE TABLE IF NOT EXISTS beans (
|
||||
id VARCHAR(50) PRIMARY KEY,
|
||||
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
roastery VARCHAR(255),
|
||||
tasting_notes TEXT,
|
||||
roast_type VARCHAR(50),
|
||||
roast_date VARCHAR(50),
|
||||
image TEXT,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
is_deleted BOOLEAN DEFAULT FALSE
|
||||
)
|
||||
`);
|
||||
|
||||
// 3. Brew logs table
|
||||
await pool.query(`
|
||||
CREATE TABLE IF NOT EXISTS brew_logs (
|
||||
id VARCHAR(50) PRIMARY KEY,
|
||||
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
|
||||
bean_id VARCHAR(50) REFERENCES beans(id) ON DELETE CASCADE,
|
||||
method VARCHAR(50),
|
||||
grind VARCHAR(100),
|
||||
water_temp VARCHAR(50),
|
||||
ratio VARCHAR(50),
|
||||
yield VARCHAR(50),
|
||||
time VARCHAR(50),
|
||||
notes TEXT,
|
||||
rating INTEGER,
|
||||
created_at BIGINT,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
is_deleted BOOLEAN DEFAULT FALSE
|
||||
)
|
||||
`);
|
||||
console.log('Database initialized');
|
||||
} catch (err) {
|
||||
console.error('Error initializing database', err);
|
||||
|
||||
Reference in New Issue
Block a user