2024-06-12 02:12:12 +00:00
|
|
|
import { Table, getTableName, sql } from 'drizzle-orm';
|
2024-06-14 00:32:09 +00:00
|
|
|
import env from '../env';
|
|
|
|
|
import { db, pool } from '$db';
|
2024-06-12 02:12:12 +00:00
|
|
|
import * as schema from './schema';
|
|
|
|
|
import * as seeds from './seeds';
|
|
|
|
|
|
2024-06-14 00:32:09 +00:00
|
|
|
if (!env.DB_SEEDING) {
|
2024-06-12 02:12:12 +00:00
|
|
|
throw new Error('You must set DB_SEEDING to "true" when running seeds');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function resetTable(db: db, table: Table) {
|
|
|
|
|
return db.execute(sql.raw(`TRUNCATE TABLE ${getTableName(table)} RESTART IDENTITY CASCADE`));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const table of [
|
|
|
|
|
schema.categories,
|
|
|
|
|
schema.categoriesToExternalIds,
|
|
|
|
|
schema.categories_to_games,
|
|
|
|
|
schema.collection_items,
|
|
|
|
|
schema.collections,
|
|
|
|
|
schema.expansions,
|
|
|
|
|
schema.externalIds,
|
|
|
|
|
schema.games,
|
|
|
|
|
schema.gamesToExternalIds,
|
|
|
|
|
schema.mechanics,
|
|
|
|
|
schema.mechanicsToExternalIds,
|
|
|
|
|
schema.mechanics_to_games,
|
|
|
|
|
schema.password_reset_tokens,
|
|
|
|
|
schema.publishers,
|
|
|
|
|
schema.publishersToExternalIds,
|
|
|
|
|
schema.publishers_to_games,
|
|
|
|
|
schema.recoveryCodes,
|
|
|
|
|
schema.roles,
|
|
|
|
|
schema.sessions,
|
|
|
|
|
schema.userRoles,
|
|
|
|
|
schema.users,
|
|
|
|
|
schema.wishlists,
|
|
|
|
|
schema.wishlist_items,
|
|
|
|
|
]) {
|
|
|
|
|
// await db.delete(table); // clear tables without truncating / resetting ids
|
|
|
|
|
await resetTable(db, table);
|
|
|
|
|
}
|
2024-02-15 01:48:47 +00:00
|
|
|
|
2024-06-12 02:12:12 +00:00
|
|
|
await seeds.roles(db);
|
2024-06-14 00:32:09 +00:00
|
|
|
await seeds.users(db);
|
2024-04-04 22:08:18 +00:00
|
|
|
|
2024-02-17 08:10:19 +00:00
|
|
|
await pool.end();
|
|
|
|
|
process.exit();
|