From 82b05573cf201e1d32400926771f46bd45663ffb Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Mon, 11 Aug 2025 17:01:00 +0300 Subject: [PATCH 1/2] fix(db-postgres): ensure index names are not too long --- .../drizzle/src/utilities/buildIndexName.ts | 7 +++- test/database/getConfig.ts | 33 +++++++++++++++++++ ...50714_201659.json => 20250811_134524.json} | 2 +- ...{20250714_201659.ts => 20250811_134524.ts} | 0 .../up-down-migration/migrations/index.ts | 8 ++--- 5 files changed, 44 insertions(+), 6 deletions(-) rename test/database/up-down-migration/migrations/{20250714_201659.json => 20250811_134524.json} (99%) rename test/database/up-down-migration/migrations/{20250714_201659.ts => 20250811_134524.ts} (100%) diff --git a/packages/drizzle/src/utilities/buildIndexName.ts b/packages/drizzle/src/utilities/buildIndexName.ts index b2d45f03ba3..31bfea266af 100644 --- a/packages/drizzle/src/utilities/buildIndexName.ts +++ b/packages/drizzle/src/utilities/buildIndexName.ts @@ -9,7 +9,12 @@ export const buildIndexName = ({ name: string number?: number }): string => { - const indexName = `${name}${number ? `_${number}` : ''}_idx` + let indexName = `${name}${number ? `_${number}` : ''}_idx` + + if (indexName.length > 60) { + // Trim to 60 chars, but keep the "_idx" suffix + indexName = `${indexName.slice(0, 60 - 4)}_idx` + } if (!adapter.indexes.has(indexName)) { adapter.indexes.add(indexName) diff --git a/test/database/getConfig.ts b/test/database/getConfig.ts index b5ea622a4f7..4d2c85d4359 100644 --- a/test/database/getConfig.ts +++ b/test/database/getConfig.ts @@ -44,6 +44,39 @@ export const getConfig: () => Partial = () => ({ type: 'text', name: 'title', }, + { + type: 'tabs', + tabs: [ + { + name: 'hideout', + fields: [ + { + label: 'Cameras', + type: 'tabs', + unique: true, + tabs: [ + { + name: 'camera1', + fields: [ + { + type: 'row', + fields: [ + { + name: 'time1Image', + type: 'relationship', + relationTo: 'posts', + unique: true, + }, + ], + }, + ], + }, + ], + }, + ], + }, + ], + }, ], }, { diff --git a/test/database/up-down-migration/migrations/20250714_201659.json b/test/database/up-down-migration/migrations/20250811_134524.json similarity index 99% rename from test/database/up-down-migration/migrations/20250714_201659.json rename to test/database/up-down-migration/migrations/20250811_134524.json index 18d7fcf69c7..208ae18fed4 100644 --- a/test/database/up-down-migration/migrations/20250714_201659.json +++ b/test/database/up-down-migration/migrations/20250811_134524.json @@ -1,5 +1,5 @@ { - "id": "80e7a0d2-ffb3-4f22-8597-0442b3ab8102", + "id": "fc114c71-8138-46c6-b83a-4d70e79e0ea5", "prevId": "00000000-0000-0000-0000-000000000000", "version": "7", "dialect": "postgresql", diff --git a/test/database/up-down-migration/migrations/20250714_201659.ts b/test/database/up-down-migration/migrations/20250811_134524.ts similarity index 100% rename from test/database/up-down-migration/migrations/20250714_201659.ts rename to test/database/up-down-migration/migrations/20250811_134524.ts diff --git a/test/database/up-down-migration/migrations/index.ts b/test/database/up-down-migration/migrations/index.ts index 8fbc100ef2c..5dc4ad50458 100644 --- a/test/database/up-down-migration/migrations/index.ts +++ b/test/database/up-down-migration/migrations/index.ts @@ -1,9 +1,9 @@ -import * as migration_20250714_201659 from './20250714_201659.js' +import * as migration_20250811_134524 from './20250811_134524.js' export const migrations = [ { - up: migration_20250714_201659.up, - down: migration_20250714_201659.down, - name: '20250714_201659', + up: migration_20250811_134524.up, + down: migration_20250811_134524.down, + name: '20250811_134524', }, ] From 7757229bab4ba24ab3a6987cdb45fe42e73ac447 Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Wed, 13 Aug 2025 13:59:22 +0300 Subject: [PATCH 2/2] fix suffix --- packages/drizzle/src/utilities/buildIndexName.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/drizzle/src/utilities/buildIndexName.ts b/packages/drizzle/src/utilities/buildIndexName.ts index 31bfea266af..16e18e5b3c2 100644 --- a/packages/drizzle/src/utilities/buildIndexName.ts +++ b/packages/drizzle/src/utilities/buildIndexName.ts @@ -12,8 +12,8 @@ export const buildIndexName = ({ let indexName = `${name}${number ? `_${number}` : ''}_idx` if (indexName.length > 60) { - // Trim to 60 chars, but keep the "_idx" suffix - indexName = `${indexName.slice(0, 60 - 4)}_idx` + const suffix = `${number ? `_${number}` : ''}_idx` + indexName = `${name.slice(0, 60 - suffix.length)}${suffix}` } if (!adapter.indexes.has(indexName)) {