fix: create inherits with table name contains upper case (#1308)

This commit is contained in:
ChengLei Shao 2022-12-31 19:16:49 +08:00 committed by GitHub
parent decf91f0a9
commit d0c7a1e39b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 3 deletions

View File

@ -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',

View File

@ -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
`,