mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00: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();
|
||
|
|
}
|
||
|
|
},
|
||
|
|
};
|