From efa0e5e56f23350f4b0a9ccb7504155d4a477ee7 Mon Sep 17 00:00:00 2001 From: arpandhakal Date: Tue, 3 Feb 2026 15:13:53 +0545 Subject: [PATCH 1/5] fix(OUT-3046): fixed uniqueIndex constraint on channelSync table --- .../20260203063809_modern_ironclad.sql | 2 + .../meta/20260203063809_snapshot.json | 503 ++++++++++++++++++ src/db/migrations/meta/_journal.json | 7 + src/db/schema/channelSync.schema.ts | 9 +- src/features/sync/lib/MapFiles.service.ts | 1 + 5 files changed, 517 insertions(+), 5 deletions(-) create mode 100644 src/db/migrations/20260203063809_modern_ironclad.sql create mode 100644 src/db/migrations/meta/20260203063809_snapshot.json diff --git a/src/db/migrations/20260203063809_modern_ironclad.sql b/src/db/migrations/20260203063809_modern_ironclad.sql new file mode 100644 index 0000000..cc81658 --- /dev/null +++ b/src/db/migrations/20260203063809_modern_ironclad.sql @@ -0,0 +1,2 @@ +DROP INDEX "uq_channel_sync_channel_id_dbx_root_path"; +CREATE UNIQUE INDEX "uq_channel_sync_channel_id_dbx_root_path" ON "channel_sync" USING btree ("assembly_channel_id","dbx_root_path") WHERE "channel_sync"."deleted_at" is null; \ No newline at end of file diff --git a/src/db/migrations/meta/20260203063809_snapshot.json b/src/db/migrations/meta/20260203063809_snapshot.json new file mode 100644 index 0000000..30f6e0c --- /dev/null +++ b/src/db/migrations/meta/20260203063809_snapshot.json @@ -0,0 +1,503 @@ +{ + "id": "b320169e-6582-49d6-8eaf-a867efa84545", + "prevId": "8ac16056-a07e-4415-8097-fadd9df642b6", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.assembly_webhook_records": { + "name": "assembly_webhook_records", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "portal_id": { + "name": "portal_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "assembly_webhook_events_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "assembly_channel_id": { + "name": "assembly_channel_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_id": { + "name": "file_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "triggered_at": { + "name": "triggered_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "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": { + "uq_all_columns_combined": { + "name": "uq_all_columns_combined", + "columns": [ + { + "expression": "portal_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "assembly_channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "file_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "triggered_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "action", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.channel_sync": { + "name": "channel_sync", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "portal_id": { + "name": "portal_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "dbx_account_id": { + "name": "dbx_account_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "assembly_channel_id": { + "name": "assembly_channel_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "dbx_root_path": { + "name": "dbx_root_path", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "dbx_root_id": { + "name": "dbx_root_id", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "dbx_cursor": { + "name": "dbx_cursor", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "total_files_count": { + "name": "total_files_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "synced_files_count": { + "name": "synced_files_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_synced_at": { + "name": "last_synced_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "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()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_channel_sync_portal_id_dbxAccount_id_deleted_at": { + "name": "idx_channel_sync_portal_id_dbxAccount_id_deleted_at", + "columns": [ + { + "expression": "portal_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "dbx_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "first" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "uq_channel_sync_channel_id_dbx_root_path": { + "name": "uq_channel_sync_channel_id_dbx_root_path", + "columns": [ + { + "expression": "assembly_channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "dbx_root_path", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"channel_sync\".\"deleted_at\" is null", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_channel_sync_portal_id_deleted_at_created_at": { + "name": "idx_channel_sync_portal_id_deleted_at_created_at", + "columns": [ + { + "expression": "portal_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "first" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dropbox_connections": { + "name": "dropbox_connections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "portal_id": { + "name": "portal_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "root_namespace_id": { + "name": "root_namespace_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "initiated_by": { + "name": "initiated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "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": { + "uq_dropbox_connections_portal_id": { + "name": "uq_dropbox_connections_portal_id", + "columns": [ + { + "expression": "portal_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.file_folder_sync": { + "name": "file_folder_sync", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "portal_id": { + "name": "portal_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "channel_sync_id": { + "name": "channel_sync_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "item_path": { + "name": "item_path", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "object": { + "name": "object", + "type": "object_types", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'file'" + }, + "content_hash": { + "name": "content_hash", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "dbx_file_id": { + "name": "dbx_file_id", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "assembly_file_id": { + "name": "assembly_file_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "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()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "file_folder_sync_channel_sync_id_channel_sync_id_fk": { + "name": "file_folder_sync_channel_sync_id_channel_sync_id_fk", + "tableFrom": "file_folder_sync", + "tableTo": "channel_sync", + "columnsFrom": ["channel_sync_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.assembly_webhook_events_enum": { + "name": "assembly_webhook_events_enum", + "schema": "public", + "values": [ + "file.created", + "file.updated", + "file.deleted", + "folder.created", + "folder.updated", + "folder.deleted" + ] + }, + "public.object_types": { + "name": "object_types", + "schema": "public", + "values": ["file", "folder"] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} diff --git a/src/db/migrations/meta/_journal.json b/src/db/migrations/meta/_journal.json index c505617..3467121 100644 --- a/src/db/migrations/meta/_journal.json +++ b/src/db/migrations/meta/_journal.json @@ -64,6 +64,13 @@ "when": 1765258299790, "tag": "20251209053139_add_combined_index_in_channel_sync", "breakpoints": false + }, + { + "idx": 9, + "version": "7", + "when": 1770100689512, + "tag": "20260203063809_modern_ironclad", + "breakpoints": false } ] } diff --git a/src/db/schema/channelSync.schema.ts b/src/db/schema/channelSync.schema.ts index f460014..9130c3f 100644 --- a/src/db/schema/channelSync.schema.ts +++ b/src/db/schema/channelSync.schema.ts @@ -1,4 +1,4 @@ -import { type InferInsertModel, type InferSelectModel, relations } from 'drizzle-orm' +import { type InferInsertModel, type InferSelectModel, isNull, relations } from 'drizzle-orm' import { boolean, index, @@ -38,10 +38,9 @@ export const channelSync = pgTable( table.dbxAccountId, table.deletedAt.nullsFirst(), ), - uniqueIndex('uq_channel_sync_channel_id_dbx_root_path').on( - table.assemblyChannelId, - table.dbxRootPath, - ), + uniqueIndex('uq_channel_sync_channel_id_dbx_root_path') + .on(table.assemblyChannelId, table.dbxRootPath) + .where(isNull(table.deletedAt)), index('idx_channel_sync_portal_id_deleted_at_created_at').on( table.portalId, table.createdAt.asc(), diff --git a/src/features/sync/lib/MapFiles.service.ts b/src/features/sync/lib/MapFiles.service.ts index c7d6c06..a43dcb8 100644 --- a/src/features/sync/lib/MapFiles.service.ts +++ b/src/features/sync/lib/MapFiles.service.ts @@ -240,6 +240,7 @@ export class MapFilesService extends AuthenticatedDropboxService { eq(channelSync.dbxAccountId, this.connectionToken.accountId), eq(channelSync.assemblyChannelId, assemblyChannelId), eq(channelSync.dbxRootPath, dbxRootPath), + isNull(channelSync.deletedAt), ), ) .returning() From 96a432b87ecaae2165280841cbdca4ee9c053a17 Mon Sep 17 00:00:00 2001 From: arpandhakal Date: Tue, 3 Feb 2026 16:19:00 +0545 Subject: [PATCH 2/5] fix(OUT-3046): dropped recent migration and applied a new one --- src/db/migrations/meta/_journal.json | 7 +++++++ src/db/schema/channelSync.schema.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/db/migrations/meta/_journal.json b/src/db/migrations/meta/_journal.json index 3467121..14194f2 100644 --- a/src/db/migrations/meta/_journal.json +++ b/src/db/migrations/meta/_journal.json @@ -71,6 +71,13 @@ "when": 1770100689512, "tag": "20260203063809_modern_ironclad", "breakpoints": false + }, + { + "idx": 10, + "version": "7", + "when": 1770114588344, + "tag": "20260203102948_add-uq-to-channel-sync", + "breakpoints": false } ] } diff --git a/src/db/schema/channelSync.schema.ts b/src/db/schema/channelSync.schema.ts index 9130c3f..e4f1559 100644 --- a/src/db/schema/channelSync.schema.ts +++ b/src/db/schema/channelSync.schema.ts @@ -38,7 +38,7 @@ export const channelSync = pgTable( table.dbxAccountId, table.deletedAt.nullsFirst(), ), - uniqueIndex('uq_channel_sync_channel_id_dbx_root_path') + uniqueIndex('uq_channel_sync__channel_id_dbx_root_path') .on(table.assemblyChannelId, table.dbxRootPath) .where(isNull(table.deletedAt)), index('idx_channel_sync_portal_id_deleted_at_created_at').on( From 6640c514c2021832ec66c44b0ce986911d36624c Mon Sep 17 00:00:00 2001 From: arpandhakal Date: Tue, 3 Feb 2026 16:19:36 +0545 Subject: [PATCH 3/5] fix(OUT-3046): dropped recent migration and applied a new one --- .../20260203102948_add-uq-to-channel-sync.sql | 5 + .../meta/20260203102948_snapshot.json | 503 ++++++++++++++++++ 2 files changed, 508 insertions(+) create mode 100644 src/db/migrations/20260203102948_add-uq-to-channel-sync.sql create mode 100644 src/db/migrations/meta/20260203102948_snapshot.json diff --git a/src/db/migrations/20260203102948_add-uq-to-channel-sync.sql b/src/db/migrations/20260203102948_add-uq-to-channel-sync.sql new file mode 100644 index 0000000..2c26e72 --- /dev/null +++ b/src/db/migrations/20260203102948_add-uq-to-channel-sync.sql @@ -0,0 +1,5 @@ +DROP INDEX IF EXISTS "uq_channel_sync_channel_id_dbx_root_path"; + +CREATE UNIQUE INDEX "uq_channel_sync__channel_id_dbx_root_path" +ON "public"."channel_sync" ("assembly_channel_id", "dbx_root_path") +WHERE "deleted_at" IS NULL; diff --git a/src/db/migrations/meta/20260203102948_snapshot.json b/src/db/migrations/meta/20260203102948_snapshot.json new file mode 100644 index 0000000..1882b06 --- /dev/null +++ b/src/db/migrations/meta/20260203102948_snapshot.json @@ -0,0 +1,503 @@ +{ + "id": "58ea31d7-0564-4680-bd44-1e6d0e4e56e2", + "prevId": "b320169e-6582-49d6-8eaf-a867efa84545", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.assembly_webhook_records": { + "name": "assembly_webhook_records", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "portal_id": { + "name": "portal_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "assembly_webhook_events_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "assembly_channel_id": { + "name": "assembly_channel_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_id": { + "name": "file_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "triggered_at": { + "name": "triggered_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "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": { + "uq_all_columns_combined": { + "name": "uq_all_columns_combined", + "columns": [ + { + "expression": "portal_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "assembly_channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "file_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "triggered_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "action", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.channel_sync": { + "name": "channel_sync", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "portal_id": { + "name": "portal_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "dbx_account_id": { + "name": "dbx_account_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "assembly_channel_id": { + "name": "assembly_channel_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "dbx_root_path": { + "name": "dbx_root_path", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "dbx_root_id": { + "name": "dbx_root_id", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "dbx_cursor": { + "name": "dbx_cursor", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "total_files_count": { + "name": "total_files_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "synced_files_count": { + "name": "synced_files_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_synced_at": { + "name": "last_synced_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "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()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_channel_sync_portal_id_dbxAccount_id_deleted_at": { + "name": "idx_channel_sync_portal_id_dbxAccount_id_deleted_at", + "columns": [ + { + "expression": "portal_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "dbx_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "first" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "uq_channel_sync__channel_id_dbx_root_path": { + "name": "uq_channel_sync__channel_id_dbx_root_path", + "columns": [ + { + "expression": "assembly_channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "dbx_root_path", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"channel_sync\".\"deleted_at\" is null", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_channel_sync_portal_id_deleted_at_created_at": { + "name": "idx_channel_sync_portal_id_deleted_at_created_at", + "columns": [ + { + "expression": "portal_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "first" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dropbox_connections": { + "name": "dropbox_connections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "portal_id": { + "name": "portal_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "root_namespace_id": { + "name": "root_namespace_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "initiated_by": { + "name": "initiated_by", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "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": { + "uq_dropbox_connections_portal_id": { + "name": "uq_dropbox_connections_portal_id", + "columns": [ + { + "expression": "portal_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.file_folder_sync": { + "name": "file_folder_sync", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "portal_id": { + "name": "portal_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "channel_sync_id": { + "name": "channel_sync_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "item_path": { + "name": "item_path", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "object": { + "name": "object", + "type": "object_types", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'file'" + }, + "content_hash": { + "name": "content_hash", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "dbx_file_id": { + "name": "dbx_file_id", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "assembly_file_id": { + "name": "assembly_file_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "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()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "file_folder_sync_channel_sync_id_channel_sync_id_fk": { + "name": "file_folder_sync_channel_sync_id_channel_sync_id_fk", + "tableFrom": "file_folder_sync", + "tableTo": "channel_sync", + "columnsFrom": ["channel_sync_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.assembly_webhook_events_enum": { + "name": "assembly_webhook_events_enum", + "schema": "public", + "values": [ + "file.created", + "file.updated", + "file.deleted", + "folder.created", + "folder.updated", + "folder.deleted" + ] + }, + "public.object_types": { + "name": "object_types", + "schema": "public", + "values": ["file", "folder"] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} From 9f798ee448b1bed2d5be622811afde983786c5ab Mon Sep 17 00:00:00 2001 From: arpandhakal Date: Tue, 3 Feb 2026 17:05:52 +0545 Subject: [PATCH 4/5] fix(OUT-3046): finalized migrations --- .../20260203063809_modern_ironclad.sql | 2 - .../20260203102948_add-uq-to-channel-sync.sql | 5 - .../20260203111950_add-uq-to-channel-sync.sql | 2 + .../meta/20260203063809_snapshot.json | 503 ------------------ ...shot.json => 20260203111950_snapshot.json} | 4 +- src/db/migrations/meta/_journal.json | 11 +- 6 files changed, 6 insertions(+), 521 deletions(-) delete mode 100644 src/db/migrations/20260203063809_modern_ironclad.sql delete mode 100644 src/db/migrations/20260203102948_add-uq-to-channel-sync.sql create mode 100644 src/db/migrations/20260203111950_add-uq-to-channel-sync.sql delete mode 100644 src/db/migrations/meta/20260203063809_snapshot.json rename src/db/migrations/meta/{20260203102948_snapshot.json => 20260203111950_snapshot.json} (99%) diff --git a/src/db/migrations/20260203063809_modern_ironclad.sql b/src/db/migrations/20260203063809_modern_ironclad.sql deleted file mode 100644 index cc81658..0000000 --- a/src/db/migrations/20260203063809_modern_ironclad.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP INDEX "uq_channel_sync_channel_id_dbx_root_path"; -CREATE UNIQUE INDEX "uq_channel_sync_channel_id_dbx_root_path" ON "channel_sync" USING btree ("assembly_channel_id","dbx_root_path") WHERE "channel_sync"."deleted_at" is null; \ No newline at end of file diff --git a/src/db/migrations/20260203102948_add-uq-to-channel-sync.sql b/src/db/migrations/20260203102948_add-uq-to-channel-sync.sql deleted file mode 100644 index 2c26e72..0000000 --- a/src/db/migrations/20260203102948_add-uq-to-channel-sync.sql +++ /dev/null @@ -1,5 +0,0 @@ -DROP INDEX IF EXISTS "uq_channel_sync_channel_id_dbx_root_path"; - -CREATE UNIQUE INDEX "uq_channel_sync__channel_id_dbx_root_path" -ON "public"."channel_sync" ("assembly_channel_id", "dbx_root_path") -WHERE "deleted_at" IS NULL; diff --git a/src/db/migrations/20260203111950_add-uq-to-channel-sync.sql b/src/db/migrations/20260203111950_add-uq-to-channel-sync.sql new file mode 100644 index 0000000..c9f03fb --- /dev/null +++ b/src/db/migrations/20260203111950_add-uq-to-channel-sync.sql @@ -0,0 +1,2 @@ +DROP INDEX "uq_channel_sync_channel_id_dbx_root_path"; +CREATE UNIQUE INDEX "uq_channel_sync__channel_id_dbx_root_path" ON "channel_sync" USING btree ("assembly_channel_id","dbx_root_path") WHERE "channel_sync"."deleted_at" is null; \ No newline at end of file diff --git a/src/db/migrations/meta/20260203063809_snapshot.json b/src/db/migrations/meta/20260203063809_snapshot.json deleted file mode 100644 index 30f6e0c..0000000 --- a/src/db/migrations/meta/20260203063809_snapshot.json +++ /dev/null @@ -1,503 +0,0 @@ -{ - "id": "b320169e-6582-49d6-8eaf-a867efa84545", - "prevId": "8ac16056-a07e-4415-8097-fadd9df642b6", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.assembly_webhook_records": { - "name": "assembly_webhook_records", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "portal_id": { - "name": "portal_id", - "type": "varchar(32)", - "primaryKey": false, - "notNull": true - }, - "action": { - "name": "action", - "type": "assembly_webhook_events_enum", - "typeSchema": "public", - "primaryKey": false, - "notNull": true - }, - "assembly_channel_id": { - "name": "assembly_channel_id", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "file_id": { - "name": "file_id", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "triggered_at": { - "name": "triggered_at", - "type": "timestamp with time zone", - "primaryKey": false, - "notNull": true - }, - "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": { - "uq_all_columns_combined": { - "name": "uq_all_columns_combined", - "columns": [ - { - "expression": "portal_id", - "isExpression": false, - "asc": true, - "nulls": "last" - }, - { - "expression": "assembly_channel_id", - "isExpression": false, - "asc": true, - "nulls": "last" - }, - { - "expression": "file_id", - "isExpression": false, - "asc": true, - "nulls": "last" - }, - { - "expression": "triggered_at", - "isExpression": false, - "asc": true, - "nulls": "last" - }, - { - "expression": "action", - "isExpression": false, - "asc": true, - "nulls": "last" - } - ], - "isUnique": true, - "concurrently": false, - "method": "btree", - "with": {} - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.channel_sync": { - "name": "channel_sync", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "portal_id": { - "name": "portal_id", - "type": "varchar(32)", - "primaryKey": false, - "notNull": true - }, - "dbx_account_id": { - "name": "dbx_account_id", - "type": "varchar(100)", - "primaryKey": false, - "notNull": true - }, - "assembly_channel_id": { - "name": "assembly_channel_id", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "dbx_root_path": { - "name": "dbx_root_path", - "type": "varchar", - "primaryKey": false, - "notNull": true - }, - "dbx_root_id": { - "name": "dbx_root_id", - "type": "varchar", - "primaryKey": false, - "notNull": false - }, - "dbx_cursor": { - "name": "dbx_cursor", - "type": "varchar", - "primaryKey": false, - "notNull": false - }, - "status": { - "name": "status", - "type": "boolean", - "primaryKey": false, - "notNull": false, - "default": false - }, - "total_files_count": { - "name": "total_files_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "synced_files_count": { - "name": "synced_files_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "last_synced_at": { - "name": "last_synced_at", - "type": "timestamp with time zone", - "primaryKey": false, - "notNull": false - }, - "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()" - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp with time zone", - "primaryKey": false, - "notNull": false - } - }, - "indexes": { - "idx_channel_sync_portal_id_dbxAccount_id_deleted_at": { - "name": "idx_channel_sync_portal_id_dbxAccount_id_deleted_at", - "columns": [ - { - "expression": "portal_id", - "isExpression": false, - "asc": true, - "nulls": "last" - }, - { - "expression": "dbx_account_id", - "isExpression": false, - "asc": true, - "nulls": "last" - }, - { - "expression": "deleted_at", - "isExpression": false, - "asc": true, - "nulls": "first" - } - ], - "isUnique": false, - "concurrently": false, - "method": "btree", - "with": {} - }, - "uq_channel_sync_channel_id_dbx_root_path": { - "name": "uq_channel_sync_channel_id_dbx_root_path", - "columns": [ - { - "expression": "assembly_channel_id", - "isExpression": false, - "asc": true, - "nulls": "last" - }, - { - "expression": "dbx_root_path", - "isExpression": false, - "asc": true, - "nulls": "last" - } - ], - "isUnique": true, - "where": "\"channel_sync\".\"deleted_at\" is null", - "concurrently": false, - "method": "btree", - "with": {} - }, - "idx_channel_sync_portal_id_deleted_at_created_at": { - "name": "idx_channel_sync_portal_id_deleted_at_created_at", - "columns": [ - { - "expression": "portal_id", - "isExpression": false, - "asc": true, - "nulls": "last" - }, - { - "expression": "created_at", - "isExpression": false, - "asc": true, - "nulls": "last" - }, - { - "expression": "deleted_at", - "isExpression": false, - "asc": true, - "nulls": "first" - } - ], - "isUnique": false, - "concurrently": false, - "method": "btree", - "with": {} - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.dropbox_connections": { - "name": "dropbox_connections", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "portal_id": { - "name": "portal_id", - "type": "varchar(32)", - "primaryKey": false, - "notNull": true - }, - "account_id": { - "name": "account_id", - "type": "varchar(100)", - "primaryKey": false, - "notNull": false - }, - "refresh_token": { - "name": "refresh_token", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false - }, - "root_namespace_id": { - "name": "root_namespace_id", - "type": "varchar(100)", - "primaryKey": false, - "notNull": false - }, - "status": { - "name": "status", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "initiated_by": { - "name": "initiated_by", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "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": { - "uq_dropbox_connections_portal_id": { - "name": "uq_dropbox_connections_portal_id", - "columns": [ - { - "expression": "portal_id", - "isExpression": false, - "asc": true, - "nulls": "last" - } - ], - "isUnique": true, - "concurrently": false, - "method": "btree", - "with": {} - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - }, - "public.file_folder_sync": { - "name": "file_folder_sync", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "portal_id": { - "name": "portal_id", - "type": "varchar(32)", - "primaryKey": false, - "notNull": true - }, - "channel_sync_id": { - "name": "channel_sync_id", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "item_path": { - "name": "item_path", - "type": "varchar", - "primaryKey": false, - "notNull": false - }, - "object": { - "name": "object", - "type": "object_types", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'file'" - }, - "content_hash": { - "name": "content_hash", - "type": "varchar", - "primaryKey": false, - "notNull": false - }, - "dbx_file_id": { - "name": "dbx_file_id", - "type": "varchar", - "primaryKey": false, - "notNull": false - }, - "assembly_file_id": { - "name": "assembly_file_id", - "type": "uuid", - "primaryKey": false, - "notNull": false - }, - "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()" - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp with time zone", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "file_folder_sync_channel_sync_id_channel_sync_id_fk": { - "name": "file_folder_sync_channel_sync_id_channel_sync_id_fk", - "tableFrom": "file_folder_sync", - "tableTo": "channel_sync", - "columnsFrom": ["channel_sync_id"], - "columnsTo": ["id"], - "onDelete": "cascade", - "onUpdate": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "policies": {}, - "checkConstraints": {}, - "isRLSEnabled": false - } - }, - "enums": { - "public.assembly_webhook_events_enum": { - "name": "assembly_webhook_events_enum", - "schema": "public", - "values": [ - "file.created", - "file.updated", - "file.deleted", - "folder.created", - "folder.updated", - "folder.deleted" - ] - }, - "public.object_types": { - "name": "object_types", - "schema": "public", - "values": ["file", "folder"] - } - }, - "schemas": {}, - "sequences": {}, - "roles": {}, - "policies": {}, - "views": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} diff --git a/src/db/migrations/meta/20260203102948_snapshot.json b/src/db/migrations/meta/20260203111950_snapshot.json similarity index 99% rename from src/db/migrations/meta/20260203102948_snapshot.json rename to src/db/migrations/meta/20260203111950_snapshot.json index 1882b06..89358bb 100644 --- a/src/db/migrations/meta/20260203102948_snapshot.json +++ b/src/db/migrations/meta/20260203111950_snapshot.json @@ -1,6 +1,6 @@ { - "id": "58ea31d7-0564-4680-bd44-1e6d0e4e56e2", - "prevId": "b320169e-6582-49d6-8eaf-a867efa84545", + "id": "0a0b3a8c-c842-43e1-9999-de9835716edb", + "prevId": "8ac16056-a07e-4415-8097-fadd9df642b6", "version": "7", "dialect": "postgresql", "tables": { diff --git a/src/db/migrations/meta/_journal.json b/src/db/migrations/meta/_journal.json index 14194f2..02f2c08 100644 --- a/src/db/migrations/meta/_journal.json +++ b/src/db/migrations/meta/_journal.json @@ -68,15 +68,8 @@ { "idx": 9, "version": "7", - "when": 1770100689512, - "tag": "20260203063809_modern_ironclad", - "breakpoints": false - }, - { - "idx": 10, - "version": "7", - "when": 1770114588344, - "tag": "20260203102948_add-uq-to-channel-sync", + "when": 1770117590888, + "tag": "20260203111950_add-uq-to-channel-sync", "breakpoints": false } ] From 907e108b5e59d63c8352cb25e8939e91e3ffc52f Mon Sep 17 00:00:00 2001 From: arpandhakal Date: Tue, 3 Feb 2026 17:12:03 +0545 Subject: [PATCH 5/5] fix(OUT-3046): finalized migrations --- src/db/migrations/20260203111950_add-uq-to-channel-sync.sql | 2 -- src/db/migrations/20260203112606_add-uq-to-channel-sync.sql | 2 ++ ...60203111950_snapshot.json => 20260203112606_snapshot.json} | 2 +- src/db/migrations/meta/_journal.json | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 src/db/migrations/20260203111950_add-uq-to-channel-sync.sql create mode 100644 src/db/migrations/20260203112606_add-uq-to-channel-sync.sql rename src/db/migrations/meta/{20260203111950_snapshot.json => 20260203112606_snapshot.json} (99%) diff --git a/src/db/migrations/20260203111950_add-uq-to-channel-sync.sql b/src/db/migrations/20260203111950_add-uq-to-channel-sync.sql deleted file mode 100644 index c9f03fb..0000000 --- a/src/db/migrations/20260203111950_add-uq-to-channel-sync.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP INDEX "uq_channel_sync_channel_id_dbx_root_path"; -CREATE UNIQUE INDEX "uq_channel_sync__channel_id_dbx_root_path" ON "channel_sync" USING btree ("assembly_channel_id","dbx_root_path") WHERE "channel_sync"."deleted_at" is null; \ No newline at end of file diff --git a/src/db/migrations/20260203112606_add-uq-to-channel-sync.sql b/src/db/migrations/20260203112606_add-uq-to-channel-sync.sql new file mode 100644 index 0000000..29e5edd --- /dev/null +++ b/src/db/migrations/20260203112606_add-uq-to-channel-sync.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS "uq_channel_sync_channel_id_dbx_root_path"; +CREATE UNIQUE INDEX IF NOT EXISTS "uq_channel_sync__channel_id_dbx_root_path" ON "channel_sync" USING btree ("assembly_channel_id","dbx_root_path") WHERE "channel_sync"."deleted_at" is null; \ No newline at end of file diff --git a/src/db/migrations/meta/20260203111950_snapshot.json b/src/db/migrations/meta/20260203112606_snapshot.json similarity index 99% rename from src/db/migrations/meta/20260203111950_snapshot.json rename to src/db/migrations/meta/20260203112606_snapshot.json index 89358bb..39aa7c1 100644 --- a/src/db/migrations/meta/20260203111950_snapshot.json +++ b/src/db/migrations/meta/20260203112606_snapshot.json @@ -1,5 +1,5 @@ { - "id": "0a0b3a8c-c842-43e1-9999-de9835716edb", + "id": "782a75df-3185-4302-9333-9ee92f0cde09", "prevId": "8ac16056-a07e-4415-8097-fadd9df642b6", "version": "7", "dialect": "postgresql", diff --git a/src/db/migrations/meta/_journal.json b/src/db/migrations/meta/_journal.json index 02f2c08..6c48860 100644 --- a/src/db/migrations/meta/_journal.json +++ b/src/db/migrations/meta/_journal.json @@ -68,8 +68,8 @@ { "idx": 9, "version": "7", - "when": 1770117590888, - "tag": "20260203111950_add-uq-to-channel-sync", + "when": 1770117966182, + "tag": "20260203112606_add-uq-to-channel-sync", "breakpoints": false } ]