Repository navigation
Expand file tree
/
Copy pathseed.js
More file actions
155 lines (143 loc) · 6.54 KB
/
Copy pathseed.js
File metadata and controls
155 lines (143 loc) · 6.54 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const bcrypt = require("bcryptjs");
const pool = require("./db");
async function seed() {
console.log("🌱 Seeding CheckD database...");
try {
const passwordHash = await bcrypt.hash("password123", 10);
// 1. Ensure primary user Arshil exists or update
const userRes = await pool.query(
`INSERT INTO users (id, name, first_name, email, password, avatar_color, bio, phone, accountability_level)
VALUES (1, 'Arshil', 'Arshil', 'arshil@example.com', $1, '#6B9E7E', 'Keeping my people healthy and happy ❤️', '+91 98765 43210', 'checkin')
ON CONFLICT (id) DO UPDATE SET
name = EXCLUDED.name,
first_name = EXCLUDED.first_name,
password = EXCLUDED.password,
avatar_color = EXCLUDED.avatar_color,
bio = EXCLUDED.bio,
phone = EXCLUDED.phone
RETURNING id, name, email`,
[passwordHash]
);
const arshilId = userRes.rows[0].id;
console.log(`✅ Main User created/updated: ${userRes.rows[0].name} (ID: ${arshilId})`);
// 2. Ensure Circle connections exist
const connectionsData = [
{ name: "Sarah", firstName: "Sarah", email: "sarah@example.com", avatarColor: "#C2796B", relationship: "partner", level: "checkin" },
{ name: "Dad", firstName: "Dad", email: "dad@example.com", avatarColor: "#7BAE8E", relationship: "parent", level: "strict" },
{ name: "Aarav", firstName: "Aarav", email: "aarav@example.com", avatarColor: "#D4A85C", relationship: "child", level: "trust" }
];
for (const conn of connectionsData) {
await pool.query(
`INSERT INTO connections (user_id, name, first_name, email, avatar_color, relationship, accountability_level)
VALUES ($1, $2, $3, $4, $5, $6, $7)
ON CONFLICT DO NOTHING`,
[arshilId, conn.name, conn.firstName, conn.email, conn.avatarColor, conn.relationship, conn.level]
);
}
console.log("✅ Accountability Circle connections seeded");
// 3. Seed sample nudges
const nudgesCount = await pool.query("SELECT COUNT(*) FROM nudges");
if (Number(nudgesCount.rows[0].count) === 0) {
const sampleNudges = [
{
title: "Take Blood Pressure Meds (Amlodipine 5mg)",
category: "medicine",
emoji: "💊",
scheduledTime: new Date(Date.now() + 30 * 60 * 1000),
repeat: "daily",
proofType: "photo",
accountability: "strict"
},
{
title: "Drink a glass of water",
category: "water",
emoji: "💧",
scheduledTime: new Date(Date.now() + 60 * 60 * 1000),
repeat: "daily",
proofType: "tap",
accountability: "trust"
},
{
title: "Evening 20-min Walk",
category: "exercise",
emoji: "🏃",
scheduledTime: new Date(Date.now() + 5 * 3600 * 1000),
repeat: "daily",
proofType: "tap",
accountability: "checkin"
}
];
for (const n of sampleNudges) {
await pool.query(
`INSERT INTO nudges (creator_id, receiver_id, category, emoji, title, scheduled_time, repeat, status, proof_type, accountability_level)
VALUES ($1, $1, $2, $3, $4, $5, $6, 'pending', $7, $8)`,
[arshilId, n.category, n.emoji, n.title, n.scheduledTime, n.repeat, n.proofType, n.accountability]
);
}
console.log("✅ Sample nudges seeded");
}
// 4. Seed sample medications (Care Cabinet)
const medCount = await pool.query("SELECT COUNT(*) FROM medications");
if (Number(medCount.rows[0].count) === 0) {
const meds = [
{
name: "Amlodipine",
dosage: "5mg",
form: "tablet",
color: "#3B82F6",
instructions: "1 tablet with breakfast daily",
currentSupply: 8,
totalCapacity: 30,
lowThreshold: 5,
doctor: "Dr. Sharma (Cardiology)"
},
{
name: "Metformin",
dosage: "500mg",
form: "tablet",
color: "#10B981",
instructions: "1 tablet with evening meal",
currentSupply: 24,
totalCapacity: 60,
lowThreshold: 10,
doctor: "Dr. Gupta (Endocrine)"
},
{
name: "Vitamin D3",
dosage: "60000 IU",
form: "capsule",
color: "#F59E0B",
instructions: "Once weekly after food",
currentSupply: 3,
totalCapacity: 8,
lowThreshold: 2,
doctor: "Dr. Patel"
}
];
for (const m of meds) {
await pool.query(
`INSERT INTO medications (person_id, name, dosage, form, color, instructions, current_supply, total_capacity, low_supply_threshold, prescribing_doctor)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`,
[arshilId, m.name, m.dosage, m.form, m.color, m.instructions, m.currentSupply, m.totalCapacity, m.lowThreshold, m.doctor]
);
}
console.log("✅ Care Cabinet medications seeded");
}
// 5. Seed initial cheer
const cheersCount = await pool.query("SELECT COUNT(*) FROM cheers");
if (Number(cheersCount.rows[0].count) === 0) {
await pool.query(
`INSERT INTO cheers (person_id, sender_id, emoji, message)
VALUES ($1, $1, '🎉', 'Super proud of your BP medicine consistency!')`,
[arshilId]
);
console.log("✅ Sample cheers seeded");
}
console.log("🎉 Seeding completed successfully!");
process.exit(0);
} catch (err) {
console.error("❌ Seeding failed:", err);
process.exit(1);
}
}
seed();