@@ -12,7 +12,9 @@ db.exec(`
1212 role TEXT NOT NULL CHECK(role IN ('farmer', 'buyer')),
1313 stellar_public_key TEXT,
1414 stellar_secret_key TEXT,
15- created_at DATETIME DEFAULT CURRENT_TIMESTAMP
15+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
16+ deactivated_at DATETIME,
17+ anonymized_at DATETIME
1618 );
1719
1820 CREATE TABLE IF NOT EXISTS products (
@@ -25,6 +27,7 @@ db.exec(`
2527 quantity INTEGER NOT NULL,
2628 unit TEXT DEFAULT 'unit',
2729 created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
30+ restock_notified_at DATETIME,
2831 FOREIGN KEY (farmer_id) REFERENCES users(id)
2932 );
3033
@@ -40,10 +43,53 @@ db.exec(`
4043 FOREIGN KEY (buyer_id) REFERENCES users(id),
4144 FOREIGN KEY (product_id) REFERENCES products(id)
4245 );
46+
47+ CREATE TABLE IF NOT EXISTS favourites (
48+ id INTEGER PRIMARY KEY AUTOINCREMENT,
49+ user_id INTEGER NOT NULL,
50+ product_id INTEGER NOT NULL,
51+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
52+ UNIQUE(user_id, product_id),
53+ FOREIGN KEY (user_id) REFERENCES users(id),
54+ FOREIGN KEY (product_id) REFERENCES products(id)
55+ );
56+
57+ CREATE TABLE IF NOT EXISTS waitlists (
58+ id INTEGER PRIMARY KEY AUTOINCREMENT,
59+ user_id INTEGER NOT NULL,
60+ product_id INTEGER NOT NULL,
61+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
62+ UNIQUE(user_id, product_id),
63+ FOREIGN KEY (user_id) REFERENCES users(id),
64+ FOREIGN KEY (product_id) REFERENCES products(id)
65+ );
66+
67+ CREATE TABLE IF NOT EXISTS push_subscriptions (
68+ id INTEGER PRIMARY KEY AUTOINCREMENT,
69+ user_id INTEGER NOT NULL UNIQUE,
70+ endpoint TEXT NOT NULL,
71+ subscription_json TEXT NOT NULL,
72+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
73+ FOREIGN KEY (user_id) REFERENCES users(id)
74+ );
75+
76+ CREATE TABLE IF NOT EXISTS address_book (
77+ id INTEGER PRIMARY KEY AUTOINCREMENT,
78+ user_id INTEGER NOT NULL,
79+ label TEXT,
80+ address TEXT,
81+ FOREIGN KEY (user_id) REFERENCES users(id)
82+ );
4383` ) ;
4484
45- // Migrate existing DB: add category column if missing
46- try { db . exec ( `ALTER TABLE products ADD COLUMN category TEXT DEFAULT 'other'` ) ; } catch { }
85+ // Migrate existing DB: add columns if missing
86+ const migrations = [
87+ `ALTER TABLE products ADD COLUMN category TEXT DEFAULT 'other'` ,
88+ `ALTER TABLE products ADD COLUMN restock_notified_at DATETIME` ,
89+ `ALTER TABLE users ADD COLUMN deactivated_at DATETIME` ,
90+ `ALTER TABLE users ADD COLUMN anonymized_at DATETIME` ,
91+ ] ;
92+ for ( const sql of migrations ) { try { db . exec ( sql ) ; } catch { } }
4793
4894module . exports = db ;
4995
0 commit comments