fix: preserve legacy accounting migration data
This commit is contained in:
1 parent
3de1530074
commit
3cdca5c82c
10 files changed
+559
-177
No files matched your search
+37
-20
@@ -28,24 +28,37 @@ export const downloadStatuses = [
|
||||
] as const;
|
||||
export const downloadStatus = pgEnum("download_status", downloadStatuses);
|
||||
|
||||
export const usages = pgTable("usages", {
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
editorialAccountId: uuid("editorial_account_id")
|
||||
.notNull()
|
||||
.references(() => editorialAccounts.id, { onDelete: "restrict" }),
|
||||
immichAssetId: uuid("immich_asset_id").notNull(),
|
||||
filenameSnapshot: text("filename_snapshot").notNull(),
|
||||
immichAlbumIdSnapshot: uuid("immich_album_id_snapshot").notNull(),
|
||||
albumNameSnapshot: text("album_name_snapshot").notNull(),
|
||||
purpose: text("purpose").notNull(),
|
||||
internalReference: text("internal_reference"),
|
||||
priceCents: integer("price_cents").notNull(),
|
||||
billingStatus: usageBillingStatus("billing_status").notNull().default("open"),
|
||||
billingReportId: uuid("billing_report_id").references(() => billingReports.id, {
|
||||
onDelete: "restrict",
|
||||
}),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
});
|
||||
export const usages = pgTable(
|
||||
"usages",
|
||||
{
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
editorialAccountId: uuid("editorial_account_id")
|
||||
.notNull()
|
||||
.references(() => editorialAccounts.id, { onDelete: "restrict" }),
|
||||
immichAssetId: text("immich_asset_id").notNull(),
|
||||
filenameSnapshot: text("filename_snapshot").notNull(),
|
||||
immichAlbumIdSnapshot: text("immich_album_id_snapshot").notNull(),
|
||||
albumNameSnapshot: text("album_name_snapshot").notNull(),
|
||||
purpose: text("purpose").notNull(),
|
||||
internalReference: text("internal_reference"),
|
||||
priceCents: integer("price_cents").notNull(),
|
||||
billingStatus: usageBillingStatus("billing_status").notNull().default("open"),
|
||||
billingReportId: uuid("billing_report_id").references(() => billingReports.id, {
|
||||
onDelete: "restrict",
|
||||
}),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(table) => [
|
||||
check(
|
||||
"usages_canonical_immich_asset_id_check",
|
||||
sql`${table.immichAssetId} ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'`,
|
||||
),
|
||||
check(
|
||||
"usages_canonical_immich_album_id_check",
|
||||
sql`${table.immichAlbumIdSnapshot} ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'`,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
export const downloadEvents = pgTable(
|
||||
"download_events",
|
||||
@@ -57,7 +70,7 @@ export const downloadEvents = pgTable(
|
||||
usageId: uuid("usage_id")
|
||||
.notNull()
|
||||
.references(() => usages.id, { onDelete: "restrict" }),
|
||||
immichAssetId: uuid("immich_asset_id").notNull(),
|
||||
immichAssetId: text("immich_asset_id").notNull(),
|
||||
authorizedAt: timestamp("authorized_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
startedAt: timestamp("started_at", { withTimezone: true }),
|
||||
completedAt: timestamp("completed_at", { withTimezone: true }),
|
||||
@@ -77,7 +90,7 @@ export const downloadEvents = pgTable(
|
||||
),
|
||||
check(
|
||||
"download_events_intent_kind_check",
|
||||
sql`${table.intentKind} in ('new_usage', 'repeat_download')`,
|
||||
sql`${table.intentKind} in ('new_usage', 'repeat_download', 'legacy')`,
|
||||
),
|
||||
check(
|
||||
"download_events_request_fingerprint_hex_check",
|
||||
@@ -87,5 +100,9 @@ export const downloadEvents = pgTable(
|
||||
"download_events_canonical_idempotency_key_check",
|
||||
sql`${table.legacyIntent} OR ${table.idempotencyKey} ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'`,
|
||||
),
|
||||
check(
|
||||
"download_events_canonical_immich_asset_id_check",
|
||||
sql`${table.immichAssetId} ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'`,
|
||||
),
|
||||
],
|
||||
);
|
||||
Reference in new issue
Block a user