add drizzle schema for legislation_texts, legislation_summaries, user_votes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
56
src/server/shared/db/schema/legislation.ts
Normal file
56
src/server/shared/db/schema/legislation.ts
Normal file
@@ -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),
|
||||
],
|
||||
)
|
||||
Reference in New Issue
Block a user