-
Notifications
You must be signed in to change notification settings - Fork 2
/
seed.ts
85 lines (77 loc) · 2.01 KB
/
seed.ts
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
import { plan } from './schema';
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import dotenv from 'dotenv';
dotenv.config();
const client = postgres(process.env.DATABASE_URL as string);
const drizzle_client = drizzle(client);
const main = async () => {
try {
console.log('Seeding database');
const freeTrialValues = {
features: ['ADD_NOTES', 'EDIT_NOTES', 'VIEW_NOTES'],
max_notes: 10,
max_members: 1,
ai_gen_max_pm: 7
};
const freeTrial = await drizzle_client
.insert(plan)
.values({
name: 'Free Trial',
...freeTrialValues
})
.onConflictDoUpdate({
target: plan.name,
set: freeTrialValues
})
.returning({ id: plan.id });
const individualPlanValues = {
features: ['ADD_NOTES', 'EDIT_NOTES', 'VIEW_NOTES', 'SPECIAL_FEATURE'],
max_notes: 100,
max_members: 1,
ai_gen_max_pm: 50,
stripe_product_id: 'prod_NQR7vwUulvIeqW'
};
const individualPlan = await drizzle_client
.insert(plan)
.values({
name: 'Individual Plan',
...individualPlanValues
})
.onConflictDoUpdate({
target: plan.name,
set: individualPlanValues
})
.returning({ id: plan.id });
const teamPlanValues = {
features: [
'ADD_NOTES',
'EDIT_NOTES',
'VIEW_NOTES',
'SPECIAL_FEATURE',
'SPECIAL_TEAM_FEATURE'
],
max_notes: 200,
max_members: 10,
ai_gen_max_pm: 500,
stripe_product_id: 'prod_NQR8IkkdhqBwu2'
};
const teamPlan = await drizzle_client
.insert(plan)
.values({
name: 'Team Plan',
...teamPlanValues
})
.onConflictDoUpdate({
target: plan.name,
set: teamPlanValues
})
.returning({ id: plan.id });
console.log({ freeTrial, individualPlan, teamPlan });
process.exit(0);
} catch (error) {
console.error(error);
throw new Error('Failed to seed database');
}
};
main();