feat(database): sync false option (#2864)

This commit is contained in:
ChengLei Shao 2023-10-19 16:12:12 +08:00 committed by GitHub
parent 9cbae661b1
commit cc676c3dda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -155,6 +155,10 @@ export class Model<TModelAttributes extends {} = any, TCreationAttributes extend
return; return;
} }
if (this.collection.options.sync === false) {
return;
}
const model = this as any; const model = this as any;
const _schema = model._schema; const _schema = model._schema;

View File

@ -15,6 +15,30 @@ describe('sync collection', () => {
await app.destroy(); await app.destroy();
}); });
it('should not sync collection that set sync false', async () => {
const c1 = db.collection({
name: 'c1',
sync: false,
fields: [{ type: 'string', name: 'f1' }],
});
await db.sync({
force: true,
});
const queryInterface = db.sequelize.getQueryInterface();
let err;
try {
await queryInterface.describeTable(c1.model.tableName);
} catch (e) {
err = e;
}
expect(err).toBeTruthy();
expect(err.message.includes('No description found')).toBeTruthy();
});
it('should not remove column when async with drop false', async () => { it('should not remove column when async with drop false', async () => {
const getTableInfo = async (tableName: string) => { const getTableInfo = async (tableName: string) => {
const queryInterface = db.sequelize.getQueryInterface(); const queryInterface = db.sequelize.getQueryInterface();