diff --git a/packages/core/database/src/__tests__/inhertits/collection-inherits.test.ts b/packages/core/database/src/__tests__/inhertits/collection-inherits.test.ts index e499bdc81..dcd93a8f4 100644 --- a/packages/core/database/src/__tests__/inhertits/collection-inherits.test.ts +++ b/packages/core/database/src/__tests__/inhertits/collection-inherits.test.ts @@ -15,6 +15,30 @@ pgOnly()('collection inherits', () => { await db.close(); }); + it('should create inherits with table name contains upperCase', async () => { + db.collection({ + name: 'parent', + fields: [{ name: 'field1', type: 'date' }], + }); + await db.sync({ + force: false, + alter: { + drop: false, + }, + }); + db.collection({ + name: 'abcABC', + inherits: ['parent'], + fields: [{ type: 'string', name: 'name' }], + }); + await db.sync({ + force: false, + alter: { + drop: false, + }, + }); + }); + it('should create inherits from empty table', async () => { const empty = db.collection({ name: 'empty', diff --git a/packages/core/database/src/sync-runner.ts b/packages/core/database/src/sync-runner.ts index 208735996..3dd0e4661 100644 --- a/packages/core/database/src/sync-runner.ts +++ b/packages/core/database/src/sync-runner.ts @@ -59,7 +59,7 @@ export class SyncRunner { throw new Error(`Can't find sequence name of ${parent}`); } - const regex = new RegExp(/nextval\('(\w+)\'.*\)/); + const regex = new RegExp(/nextval\('("?\w+"?)\'.*\)/); const match = regex.exec(columnDefault); const sequenceName = match[1]; @@ -90,11 +90,13 @@ export class SyncRunner { const sequenceTables = [...parentsDeep, tableName]; for (const sequenceTable of sequenceTables) { + const queryName = Boolean(sequenceTable.match(/[A-Z]/)) ? `"${sequenceTable}"` : sequenceTable; + const idColumnQuery = await queryInterface.sequelize.query( ` - SELECT true +SELECT true FROM pg_attribute -WHERE attrelid = '${sequenceTable}'::regclass -- cast to a registered class (table) +WHERE attrelid = '${queryName}'::regclass -- cast to a registered class (table) AND attname = 'id' AND NOT attisdropped `,