Add external model persistence foundation

This commit is contained in:
Julian Appel 2026-08-02 17:18:24 +02:00
parent d0fc1a7caf
commit 76493b573e
15 changed files with 3207 additions and 8 deletions

View file

@ -0,0 +1,43 @@
import { blob, index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
import type {
ExternalCsvConfiguration,
ExternalCsvDocument,
} from "../../external-model/csv/external-csv-contracts.js";
import { externalImportKinds } from "../../external-model/domain/external-model-contracts.js";
import { externalModelSources } from "./external-model-sources.js";
import { projects } from "./projects.js";
export const externalImportBatches = sqliteTable(
"external_import_batches",
{
id: text("id").primaryKey(),
projectId: text("project_id")
.notNull()
.references(() => projects.id, { onDelete: "cascade" }),
sourceId: text("source_id")
.notNull()
.references(() => externalModelSources.id, { onDelete: "cascade" }),
importKind: text("import_kind", { enum: externalImportKinds }).notNull(),
importedAtIso: text("imported_at_iso").notNull(),
fileName: text("file_name").notNull(),
sha256: text("sha256").notNull(),
appliedProjectRevision: integer("applied_project_revision").notNull(),
configurationSnapshot: text("configuration_snapshot", { mode: "json" })
.$type<ExternalCsvConfiguration>()
.notNull(),
originalBytes: blob("original_bytes", { mode: "buffer" }).notNull(),
document: text("document", { mode: "json" })
.$type<ExternalCsvDocument>()
.notNull(),
},
(table) => [
index("external_import_batches_project_revision_idx").on(
table.projectId,
table.appliedProjectRevision
),
index("external_import_batches_source_imported_idx").on(
table.sourceId,
table.importedAtIso
),
]
);