first commit

This commit is contained in:
2026-06-10 18:30:46 +02:00
parent 3e7b0ae2e0
commit cabd4803a4
39 changed files with 3635 additions and 81 deletions
+36
View File
@@ -0,0 +1,36 @@
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "./schema";
const connectionString = process.env.DATABASE_URL;
let client: ReturnType<typeof postgres> | null = null;
let db: ReturnType<typeof drizzle<typeof schema>> | null = null;
export function getDb() {
if (!connectionString) {
throw new Error("DATABASE_URL is not set");
}
if (!client) {
client = postgres(connectionString, { max: 10 });
db = drizzle(client, { schema });
}
return db!;
}
export async function checkDbConnection(): Promise<boolean> {
if (!connectionString) {
return false;
}
try {
const probe = postgres(connectionString, { max: 1 });
await probe`SELECT 1`;
await probe.end();
return true;
} catch {
return false;
}
}
+28
View File
@@ -0,0 +1,28 @@
import {
integer,
jsonb,
pgTable,
serial,
timestamp,
uniqueIndex,
varchar,
} from "drizzle-orm/pg-core";
export const cardCache = pgTable(
"card_cache",
{
id: serial("id").primaryKey(),
movieId: integer("movie_id").notNull(),
cardType: varchar("card_type", { length: 50 }).notNull(),
payload: jsonb("payload").notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
.defaultNow()
.notNull(),
},
(table) => [
uniqueIndex("card_cache_movie_card_unique").on(
table.movieId,
table.cardType,
),
],
);