fix: restore with table name in camel case (#3995)

This commit is contained in:
ChengLei Shao 2024-04-09 19:10:29 +08:00 committed by GitHub
parent 773b7aef52
commit 1e0501cd96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 68 additions and 1 deletions

View File

@ -124,7 +124,7 @@ export default class MysqlQueryInterface extends QueryInterface {
}): Promise<void> {
const { tableInfo, columnName, seqName, currentVal, transaction } = options;
const sql = `ALTER TABLE ${tableInfo.tableName} AUTO_INCREMENT = ${currentVal};`;
const sql = `ALTER TABLE ${this.quoteIdentifier(tableInfo.tableName)} AUTO_INCREMENT = ${currentVal};`;
await this.db.sequelize.query(sql, { transaction });
}
}

View File

@ -64,4 +64,9 @@ export default abstract class QueryInterface {
currentVal: number;
transaction?: Transaction;
}): Promise<void>;
public quoteIdentifier(identifier: string) {
// @ts-ignore
return this.db.sequelize.getQueryInterface().queryGenerator.quoteIdentifier(identifier);
}
}

View File

@ -828,4 +828,66 @@ describe('dumper', () => {
expect(dumpableCollections.custom).toBeDefined();
});
it('should dump and restore with table named by camel case', async () => {
await app.db.getRepository('collections').create({
values: {
name: 'Resumes-Table',
fields: [
{
name: 'stringField',
type: 'string',
},
],
},
context: {},
});
await app.db.getRepository('Resumes-Table').create({
values: [
{
stringField: 'test',
},
{
stringField: 'test2',
},
],
});
await app.db.getRepository('collections').create({
values: {
name: 'Photos',
fields: [
{
name: 'stringField',
type: 'string',
},
],
},
context: {},
});
await app.db.getRepository('Photos').create({
values: [
{
stringField: 'test',
},
{
stringField: 'test2',
},
],
});
const dumper = new Dumper(app);
const result = await dumper.dump({
groups: new Set(['required', 'custom']),
});
const restorer = new Restorer(app, {
backUpFilePath: result.filePath,
});
await restorer.restore({
groups: new Set(['required', 'custom']),
});
});
});