Add events table

This commit is contained in:
cte 2025-05-13 23:24:02 -07:00
parent 331c26afec
commit 1fa656a012
5 changed files with 179 additions and 6 deletions

View file

@ -6,6 +6,6 @@ set -u
if [ -n "$POSTGRES_DATABASES" ]; then
for db in $(echo $POSTGRES_DATABASES | tr ',' ' '); do
echo "Creating $db..."
psql -v ON_ERROR_STOP=1 -c "CREATE DATABASE $db;"
psql -U postgres -v ON_ERROR_STOP=1 -c "CREATE DATABASE $db;"
done
fi

View file

@ -0,0 +1,8 @@
CREATE TABLE "event" (
"id" text PRIMARY KEY NOT NULL,
"type" text NOT NULL,
"timestamp" bigint NOT NULL,
"properties" json NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);

View file

@ -0,0 +1,149 @@
{
"id": "37608d29-a721-43ec-91e6-c4a356d23b3e",
"prevId": "013accf9-070a-47cd-9b49-1318a1c8a237",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.event": {
"name": "event",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"type": {
"name": "type",
"type": "text",
"primaryKey": false,
"notNull": true
},
"timestamp": {
"name": "timestamp",
"type": "bigint",
"primaryKey": false,
"notNull": true
},
"properties": {
"name": "properties",
"type": "json",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.organization": {
"name": "organization",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"stripe_customer_id": {
"name": "stripe_customer_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"stripe_subscription_id": {
"name": "stripe_subscription_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"stripe_subscription_price_id": {
"name": "stripe_subscription_price_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"stripe_subscription_status": {
"name": "stripe_subscription_status",
"type": "text",
"primaryKey": false,
"notNull": false
},
"stripe_subscription_current_period_end": {
"name": "stripe_subscription_current_period_end",
"type": "bigint",
"primaryKey": false,
"notNull": false
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"stripe_customer_id_idx": {
"name": "stripe_customer_id_idx",
"columns": [
{
"expression": "stripe_customer_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View file

@ -8,6 +8,13 @@
"when": 1747031111132,
"tag": "0000_misty_leo",
"breakpoints": true
},
{
"idx": 1,
"version": "7",
"when": 1747203099634,
"tag": "0001_glamorous_thunderbird",
"breakpoints": true
}
]
}

View file

@ -4,6 +4,7 @@ import {
text,
timestamp,
uniqueIndex,
json,
} from 'drizzle-orm/pg-core';
export const organizationSchema = pgTable(
@ -24,9 +25,17 @@ export const organizationSchema = pgTable(
.notNull(),
createdAt: timestamp('created_at', { mode: 'date' }).defaultNow().notNull(),
},
(table) => ({
stripeCustomerIdIdx: uniqueIndex('stripe_customer_id_idx').on(
table.stripeCustomerId,
),
}),
(table) => [uniqueIndex('stripe_customer_id_idx').on(table.stripeCustomerId)],
);
export const eventSchema = pgTable('event', {
id: text('id').primaryKey(),
type: text('type').notNull(),
timestamp: bigint('timestamp', { mode: 'number' }).notNull(),
properties: json('properties').notNull(),
createdAt: timestamp('created_at', { mode: 'date' }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { mode: 'date' })
.defaultNow()
.$onUpdate(() => new Date())
.notNull(),
});