mirror of
https://github.com/immich-app/immich.git
synced 2025-01-09 05:16:47 +01:00
25 lines
601 B
TypeScript
25 lines
601 B
TypeScript
|
import { dataSource } from '@app/infra';
|
||
|
|
||
|
export const db = {
|
||
|
reset: async () => {
|
||
|
if (!dataSource.isInitialized) {
|
||
|
await dataSource.initialize();
|
||
|
}
|
||
|
|
||
|
await dataSource.transaction(async (em) => {
|
||
|
for (const entity of dataSource.entityMetadatas) {
|
||
|
if (entity.tableName === 'users') {
|
||
|
continue;
|
||
|
}
|
||
|
await em.query(`DELETE FROM ${entity.tableName} CASCADE;`);
|
||
|
}
|
||
|
await em.query(`DELETE FROM "users" CASCADE;`);
|
||
|
});
|
||
|
},
|
||
|
disconnect: async () => {
|
||
|
if (dataSource.isInitialized) {
|
||
|
await dataSource.destroy();
|
||
|
}
|
||
|
},
|
||
|
};
|