Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions __tests__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,16 @@ const cleanDatabase = async (): Promise<void> => {
await remoteConfig.init();

const con = await createOrGetConnection();
for (const entity of con.entityMetadatas) {
const repository = con.getRepository(entity.name);
if (repository.metadata.tableType === 'view') continue;
await repository.query(`DELETE
FROM "${entity.tableName}";`);

for (const column of entity.primaryColumns) {
if (column.generationStrategy === 'increment') {
await repository.query(
`ALTER SEQUENCE ${entity.tableName}_${column.databaseName}_seq RESTART WITH 1`,
);
}
}
}
// Get all table names, excluding views
const tableNames = con.entityMetadatas
.filter((entity) => entity.tableType !== 'view')
.map((entity) => `"${entity.tableName}"`)
.join(', ');

// Single TRUNCATE with CASCADE and RESTART IDENTITY
// Much faster than individual DELETE statements per table
await con.query(`TRUNCATE TABLE ${tableNames} RESTART IDENTITY CASCADE`);
};

export const fileTypeFromBuffer = jest.fn();
Expand Down
Loading