40 lines
1.7 KiB
TypeScript
40 lines
1.7 KiB
TypeScript
import { blob, index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
import type { ExternalModelConfiguration } from "../../external-model/configuration/external-model-configuration.js";
|
|
import { externalImportKinds } from "../../external-model/domain/external-model-contracts.js";
|
|
import type { ExternalXlsxDocument } from "../../external-model/xlsx/external-xlsx-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(),
|
|
objectCount: integer("object_count").notNull(),
|
|
appliedProjectRevision: integer("applied_project_revision"),
|
|
configurationSnapshot: text("configuration_snapshot", { mode: "json" })
|
|
.$type<ExternalModelConfiguration>(),
|
|
originalBytes: blob("original_bytes", { mode: "buffer" }),
|
|
document: text("document", { mode: "json" })
|
|
.$type<ExternalXlsxDocument>(),
|
|
},
|
|
(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
|
|
),
|
|
]
|
|
);
|