Skip to content

Commit 1fa656a

Browse files
committed
Add events table
1 parent 331c26a commit 1fa656a

File tree

5 files changed

+179
-6
lines changed

5 files changed

+179
-6
lines changed

.docker/scripts/postgres/create-databases.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ set -u
66
if [ -n "$POSTGRES_DATABASES" ]; then
77
for db in $(echo $POSTGRES_DATABASES | tr ',' ' '); do
88
echo "Creating $db..."
9-
psql -v ON_ERROR_STOP=1 -c "CREATE DATABASE $db;"
9+
psql -U postgres -v ON_ERROR_STOP=1 -c "CREATE DATABASE $db;"
1010
done
1111
fi
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CREATE TABLE "event" (
2+
"id" text PRIMARY KEY NOT NULL,
3+
"type" text NOT NULL,
4+
"timestamp" bigint NOT NULL,
5+
"properties" json NOT NULL,
6+
"created_at" timestamp DEFAULT now() NOT NULL,
7+
"updated_at" timestamp DEFAULT now() NOT NULL
8+
);

migrations/meta/0001_snapshot.json

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"id": "37608d29-a721-43ec-91e6-c4a356d23b3e",
3+
"prevId": "013accf9-070a-47cd-9b49-1318a1c8a237",
4+
"version": "7",
5+
"dialect": "postgresql",
6+
"tables": {
7+
"public.event": {
8+
"name": "event",
9+
"schema": "",
10+
"columns": {
11+
"id": {
12+
"name": "id",
13+
"type": "text",
14+
"primaryKey": true,
15+
"notNull": true
16+
},
17+
"type": {
18+
"name": "type",
19+
"type": "text",
20+
"primaryKey": false,
21+
"notNull": true
22+
},
23+
"timestamp": {
24+
"name": "timestamp",
25+
"type": "bigint",
26+
"primaryKey": false,
27+
"notNull": true
28+
},
29+
"properties": {
30+
"name": "properties",
31+
"type": "json",
32+
"primaryKey": false,
33+
"notNull": true
34+
},
35+
"created_at": {
36+
"name": "created_at",
37+
"type": "timestamp",
38+
"primaryKey": false,
39+
"notNull": true,
40+
"default": "now()"
41+
},
42+
"updated_at": {
43+
"name": "updated_at",
44+
"type": "timestamp",
45+
"primaryKey": false,
46+
"notNull": true,
47+
"default": "now()"
48+
}
49+
},
50+
"indexes": {},
51+
"foreignKeys": {},
52+
"compositePrimaryKeys": {},
53+
"uniqueConstraints": {},
54+
"policies": {},
55+
"checkConstraints": {},
56+
"isRLSEnabled": false
57+
},
58+
"public.organization": {
59+
"name": "organization",
60+
"schema": "",
61+
"columns": {
62+
"id": {
63+
"name": "id",
64+
"type": "text",
65+
"primaryKey": true,
66+
"notNull": true
67+
},
68+
"stripe_customer_id": {
69+
"name": "stripe_customer_id",
70+
"type": "text",
71+
"primaryKey": false,
72+
"notNull": false
73+
},
74+
"stripe_subscription_id": {
75+
"name": "stripe_subscription_id",
76+
"type": "text",
77+
"primaryKey": false,
78+
"notNull": false
79+
},
80+
"stripe_subscription_price_id": {
81+
"name": "stripe_subscription_price_id",
82+
"type": "text",
83+
"primaryKey": false,
84+
"notNull": false
85+
},
86+
"stripe_subscription_status": {
87+
"name": "stripe_subscription_status",
88+
"type": "text",
89+
"primaryKey": false,
90+
"notNull": false
91+
},
92+
"stripe_subscription_current_period_end": {
93+
"name": "stripe_subscription_current_period_end",
94+
"type": "bigint",
95+
"primaryKey": false,
96+
"notNull": false
97+
},
98+
"updated_at": {
99+
"name": "updated_at",
100+
"type": "timestamp",
101+
"primaryKey": false,
102+
"notNull": true,
103+
"default": "now()"
104+
},
105+
"created_at": {
106+
"name": "created_at",
107+
"type": "timestamp",
108+
"primaryKey": false,
109+
"notNull": true,
110+
"default": "now()"
111+
}
112+
},
113+
"indexes": {
114+
"stripe_customer_id_idx": {
115+
"name": "stripe_customer_id_idx",
116+
"columns": [
117+
{
118+
"expression": "stripe_customer_id",
119+
"isExpression": false,
120+
"asc": true,
121+
"nulls": "last"
122+
}
123+
],
124+
"isUnique": true,
125+
"concurrently": false,
126+
"method": "btree",
127+
"with": {}
128+
}
129+
},
130+
"foreignKeys": {},
131+
"compositePrimaryKeys": {},
132+
"uniqueConstraints": {},
133+
"policies": {},
134+
"checkConstraints": {},
135+
"isRLSEnabled": false
136+
}
137+
},
138+
"enums": {},
139+
"schemas": {},
140+
"sequences": {},
141+
"roles": {},
142+
"policies": {},
143+
"views": {},
144+
"_meta": {
145+
"columns": {},
146+
"schemas": {},
147+
"tables": {}
148+
}
149+
}

migrations/meta/_journal.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
"when": 1747031111132,
99
"tag": "0000_misty_leo",
1010
"breakpoints": true
11+
},
12+
{
13+
"idx": 1,
14+
"version": "7",
15+
"when": 1747203099634,
16+
"tag": "0001_glamorous_thunderbird",
17+
"breakpoints": true
1118
}
1219
]
1320
}

src/db/schema.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
text,
55
timestamp,
66
uniqueIndex,
7+
json,
78
} from 'drizzle-orm/pg-core';
89

910
export const organizationSchema = pgTable(
@@ -24,9 +25,17 @@ export const organizationSchema = pgTable(
2425
.notNull(),
2526
createdAt: timestamp('created_at', { mode: 'date' }).defaultNow().notNull(),
2627
},
27-
(table) => ({
28-
stripeCustomerIdIdx: uniqueIndex('stripe_customer_id_idx').on(
29-
table.stripeCustomerId,
30-
),
31-
}),
28+
(table) => [uniqueIndex('stripe_customer_id_idx').on(table.stripeCustomerId)],
3229
);
30+
31+
export const eventSchema = pgTable('event', {
32+
id: text('id').primaryKey(),
33+
type: text('type').notNull(),
34+
timestamp: bigint('timestamp', { mode: 'number' }).notNull(),
35+
properties: json('properties').notNull(),
36+
createdAt: timestamp('created_at', { mode: 'date' }).defaultNow().notNull(),
37+
updatedAt: timestamp('updated_at', { mode: 'date' })
38+
.defaultNow()
39+
.$onUpdate(() => new Date())
40+
.notNull(),
41+
});

0 commit comments

Comments
 (0)