fix: rebuild migration history as baseline so migrate works on prod

Squash the 13 historical migrations into one generated baseline whose
journal entry reuses the original 0000 timestamp: the migrator skips it
on every existing database (prod journal stuck at 0006) and applies it
only on fresh ones. Parity with the old chain verified via pg_dump diff
plus fresh/existing/prod-simulated drizzle-kit migrate runs. Historical
files move to drizzle-history/pre-squash-2026-08/ for integration tests
that exercise legacy migration behavior.

Also repair db tests that already failed before this change:
- raw SQL targeted users, but the table has always been "user"
- membership recheck mocked legacy getAsset.albums instead of searchPhotos
- audit rollback assertion walks drizzle's wrapped error cause chain
- keyset index probe pinned to NULLS LAST ordering, removing a planner
  cost tie-break that flipped with index creation order
This commit is contained in:
Leon Tonhäuser committed 2026-08-25 11:56:52 +02:00
1 parent 2949149170
commit 0b65fbba16
40 files changed
+2389 -128

No files matched your search

+517 -6
View File
@@ -1,5 +1,5 @@
{
"id": "64eb37ed-2ab5-4c12-a8be-4375e8f6a732",
"id": "5ac645f2-0e76-4853-b029-724095bf1138",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
@@ -77,6 +77,28 @@
"concurrently": false,
"method": "btree",
"with": {}
},
"album_grants_editorial_active_album_unique": {
"name": "album_grants_editorial_active_album_unique",
"columns": [
{
"expression": "editorial_account_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "lower(\"immich_album_id\")",
"asc": true,
"isExpression": true,
"nulls": "last"
}
],
"isUnique": true,
"where": "\"album_grants\".\"revoked_at\" is null",
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
@@ -110,7 +132,12 @@
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"checkConstraints": {
"album_grants_immich_album_id_uuid_check": {
"name": "album_grants_immich_album_id_uuid_check",
"value": "\"album_grants\".\"immich_album_id\" ~* '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'"
}
},
"isRLSEnabled": false
},
"public.audit_events": {
@@ -397,6 +424,86 @@
"checkConstraints": {},
"isRLSEnabled": false
},
"public.two_factor": {
"name": "two_factor",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"user_id": {
"name": "user_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"secret": {
"name": "secret",
"type": "text",
"primaryKey": false,
"notNull": true
},
"backup_codes": {
"name": "backup_codes",
"type": "text",
"primaryKey": false,
"notNull": false
},
"verified": {
"name": "verified",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"failed_verification_count": {
"name": "failed_verification_count",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 0
},
"locked_until": {
"name": "locked_until",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"two_factor_user_id_user_id_fk": {
"name": "two_factor_user_id_user_id_fk",
"tableFrom": "two_factor",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "restrict",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"two_factor_user_id_unique": {
"name": "two_factor_user_id_unique",
"nullsNotDistinct": false,
"columns": [
"user_id"
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.user": {
"name": "user",
"schema": "",
@@ -441,6 +548,13 @@
"notNull": true,
"default": "'EDITORIAL'"
},
"two_factor_enabled": {
"name": "two_factor_enabled",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
@@ -524,6 +638,100 @@
"checkConstraints": {},
"isRLSEnabled": false
},
"public.album_auto_rules": {
"name": "album_auto_rules",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"editorial_account_id": {
"name": "editorial_account_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"keyword": {
"name": "keyword",
"type": "text",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"created_by_user_id": {
"name": "created_by_user_id",
"type": "uuid",
"primaryKey": false,
"notNull": false
}
},
"indexes": {
"album_auto_rules_editorial_account_id_keyword_idx": {
"name": "album_auto_rules_editorial_account_id_keyword_idx",
"columns": [
{
"expression": "editorial_account_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "lower(\"keyword\")",
"asc": true,
"isExpression": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"album_auto_rules_editorial_account_id_editorial_accounts_id_fk": {
"name": "album_auto_rules_editorial_account_id_editorial_accounts_id_fk",
"tableFrom": "album_auto_rules",
"tableTo": "editorial_accounts",
"columnsFrom": [
"editorial_account_id"
],
"columnsTo": [
"id"
],
"onDelete": "restrict",
"onUpdate": "no action"
},
"album_auto_rules_created_by_user_id_user_id_fk": {
"name": "album_auto_rules_created_by_user_id_user_id_fk",
"tableFrom": "album_auto_rules",
"tableTo": "user",
"columnsFrom": [
"created_by_user_id"
],
"columnsTo": [
"id"
],
"onDelete": "restrict",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.billing_report_items": {
"name": "billing_report_items",
"schema": "",
@@ -701,6 +909,12 @@
"primaryKey": false,
"notNull": true
},
"flatrate_cents_snapshot": {
"name": "flatrate_cents_snapshot",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"status": {
"name": "status",
"type": "report_status",
@@ -1030,6 +1244,32 @@
"primaryKey": false,
"notNull": false
},
"flatrate_active": {
"name": "flatrate_active",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"flatrate_price_cents": {
"name": "flatrate_price_cents",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"flatrate_asset_limit": {
"name": "flatrate_asset_limit",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"approval_notice_status": {
"name": "approval_notice_status",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'not_requested'"
},
"current_billing_address_version_id": {
"name": "current_billing_address_version_id",
"type": "uuid",
@@ -1060,6 +1300,18 @@
"primaryKey": false,
"notNull": false
},
"archived_at": {
"name": "archived_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
},
"archived_by_user_id": {
"name": "archived_by_user_id",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
@@ -1102,6 +1354,19 @@
],
"onDelete": "restrict",
"onUpdate": "no action"
},
"editorial_accounts_archived_by_user_id_user_id_fk": {
"name": "editorial_accounts_archived_by_user_id_user_id_fk",
"tableFrom": "editorial_accounts",
"tableTo": "user",
"columnsFrom": [
"archived_by_user_id"
],
"columnsTo": [
"id"
],
"onDelete": "restrict",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
@@ -1125,6 +1390,135 @@
"checkConstraints": {},
"isRLSEnabled": false
},
"public.lightbox_items": {
"name": "lightbox_items",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"editorial_account_id": {
"name": "editorial_account_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"asset_id": {
"name": "asset_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"added_at": {
"name": "added_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"lightbox_items_editorial_asset_idx": {
"name": "lightbox_items_editorial_asset_idx",
"columns": [
{
"expression": "editorial_account_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "asset_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"lightbox_items_editorial_account_id_editorial_accounts_id_fk": {
"name": "lightbox_items_editorial_account_id_editorial_accounts_id_fk",
"tableFrom": "lightbox_items",
"tableTo": "editorial_accounts",
"columnsFrom": [
"editorial_account_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.rate_limits": {
"name": "rate_limits",
"schema": "",
"columns": {
"key": {
"name": "key",
"type": "text",
"primaryKey": false,
"notNull": true
},
"window_boundary": {
"name": "window_boundary",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"count": {
"name": "count",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 1
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"rate_limits_key_window_boundary_pk": {
"name": "rate_limits_key_window_boundary_pk",
"columns": [
"key",
"window_boundary"
]
}
},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.download_events": {
"name": "download_events",
"schema": "",
@@ -1204,9 +1598,56 @@
"type": "text",
"primaryKey": false,
"notNull": true
},
"intent_kind": {
"name": "intent_kind",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'new_usage'"
},
"request_fingerprint": {
"name": "request_fingerprint",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true
},
"legacy_intent": {
"name": "legacy_intent",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
}
},
"indexes": {
"download_events_editorial_authorized_id_idx": {
"name": "download_events_editorial_authorized_id_idx",
"columns": [
{
"expression": "editorial_account_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "authorized_at",
"isExpression": false,
"asc": false,
"nulls": "last"
},
{
"expression": "id",
"isExpression": false,
"asc": false,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"download_events_editorial_idempotency_key_unique": {
"name": "download_events_editorial_idempotency_key_unique",
"columns": [
@@ -1260,7 +1701,24 @@
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"checkConstraints": {
"download_events_intent_kind_check": {
"name": "download_events_intent_kind_check",
"value": "\"download_events\".\"intent_kind\" in ('new_usage', 'repeat_download', 'legacy')"
},
"download_events_request_fingerprint_hex_check": {
"name": "download_events_request_fingerprint_hex_check",
"value": "\"download_events\".\"request_fingerprint\" ~ '^[0-9a-f]{64}$'"
},
"download_events_canonical_idempotency_key_check": {
"name": "download_events_canonical_idempotency_key_check",
"value": "\"download_events\".\"legacy_intent\" OR \"download_events\".\"idempotency_key\" ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'"
},
"download_events_canonical_immich_asset_id_check": {
"name": "download_events_canonical_immich_asset_id_check",
"value": "\"download_events\".\"immich_asset_id\" ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'"
}
},
"isRLSEnabled": false
},
"public.usages": {
@@ -1344,7 +1802,50 @@
"default": "now()"
}
},
"indexes": {},
"indexes": {
"usages_editorial_created_id_idx": {
"name": "usages_editorial_created_id_idx",
"columns": [
{
"expression": "editorial_account_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "created_at",
"isExpression": false,
"asc": false,
"nulls": "last"
},
{
"expression": "id",
"isExpression": false,
"asc": false,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"usages_created_at_idx": {
"name": "usages_created_at_idx",
"columns": [
{
"expression": "created_at",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"usages_editorial_account_id_editorial_accounts_id_fk": {
"name": "usages_editorial_account_id_editorial_accounts_id_fk",
@@ -1376,7 +1877,16 @@
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"checkConstraints": {
"usages_canonical_immich_asset_id_check": {
"name": "usages_canonical_immich_asset_id_check",
"value": "\"usages\".\"immich_asset_id\" ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'"
},
"usages_canonical_immich_album_id_check": {
"name": "usages_canonical_immich_album_id_check",
"value": "\"usages\".\"immich_album_id_snapshot\" ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'"
}
},
"isRLSEnabled": false
}
},
@@ -1426,7 +1936,8 @@
"values": [
"open",
"billed",
"reopened"
"reopened",
"voided"
]
}
},