mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 09:29:16 +00:00
fix: create inherits with table name contains upper case (#1308)
This commit is contained in:
parent
decf91f0a9
commit
d0c7a1e39b
@ -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',
|
||||
|
@ -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
|
||||
`,
|
||||
|
Loading…
Reference in New Issue
Block a user