feat(database): sync false option (#2864)
This commit is contained in:
		
							parent
							
								
									9cbae661b1
								
							
						
					
					
						commit
						cc676c3dda
					
				@ -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;
 | 
				
			||||||
 | 
				
			|||||||
@ -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();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user