From 06745c240eb368be362d8e81c6fe2d26de2018f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20F=C3=B6rtsch?= Date: Tue, 10 Mar 2026 16:44:07 +0100 Subject: [PATCH] add drizzle schema for legislation_texts, legislation_summaries, user_votes Co-Authored-By: Claude Sonnet 4.6 --- src/server/shared/db/client.ts | 3 +- src/server/shared/db/schema/legislation.ts | 56 ++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/server/shared/db/schema/legislation.ts diff --git a/src/server/shared/db/client.ts b/src/server/shared/db/client.ts index 5c2c979..94864c0 100644 --- a/src/server/shared/db/client.ts +++ b/src/server/shared/db/client.ts @@ -1,12 +1,13 @@ import { drizzle } from "drizzle-orm/postgres-js" import postgres from "postgres" import { env } from "../lib/env" +import * as legislationSchema from "./schema/legislation" import * as politicianSchema from "./schema/politicians" import * as pushSchema from "./schema/push" const sql = postgres(env.DATABASE_URL) export const db = drizzle(sql, { - schema: { ...pushSchema, ...politicianSchema }, + schema: { ...pushSchema, ...politicianSchema, ...legislationSchema }, }) export type Database = typeof db diff --git a/src/server/shared/db/schema/legislation.ts b/src/server/shared/db/schema/legislation.ts new file mode 100644 index 0000000..29e24f1 --- /dev/null +++ b/src/server/shared/db/schema/legislation.ts @@ -0,0 +1,56 @@ +import { + integer, + pgTable, + text, + timestamp, + unique, + uuid, + varchar, +} from "drizzle-orm/pg-core" + +export const legislationTexts = pgTable("legislation_texts", { + id: integer("id").primaryKey().generatedAlwaysAsIdentity(), + dipVorgangsId: integer("dip_vorgangs_id").notNull().unique(), + title: text("title").notNull(), + abstract: text("abstract"), + fullText: text("full_text"), + drucksacheUrl: text("drucksache_url"), + beratungsstand: text("beratungsstand"), + pollId: integer("poll_id"), + fetchedAt: timestamp("fetched_at", { withTimezone: true }) + .notNull() + .defaultNow(), + expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(), +}) + +export const legislationSummaries = pgTable("legislation_summaries", { + id: integer("id").primaryKey().generatedAlwaysAsIdentity(), + legislationId: integer("legislation_id") + .notNull() + .references(() => legislationTexts.id, { onDelete: "cascade" }) + .unique(), + summary: text("summary").notNull(), + generatedAt: timestamp("generated_at", { withTimezone: true }) + .notNull() + .defaultNow(), +}) + +export const userVotes = pgTable( + "user_votes", + { + id: integer("id").primaryKey().generatedAlwaysAsIdentity(), + deviceId: uuid("device_id").notNull(), + legislationId: integer("legislation_id") + .notNull() + .references(() => legislationTexts.id, { onDelete: "cascade" }), + vote: varchar("vote", { length: 20 }) + .notNull() + .$type<"ja" | "nein" | "enthaltung">(), + votedAt: timestamp("voted_at", { withTimezone: true }) + .notNull() + .defaultNow(), + }, + (t) => [ + unique("user_votes_device_legislation").on(t.deviceId, t.legislationId), + ], +)