Skip to content

Commit

Permalink
feat: generalize table drop
Browse files Browse the repository at this point in the history
  • Loading branch information
yamcodes committed Oct 8, 2023
1 parent e0a1dcb commit b8b6689
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions db/drop.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import { db } from '@/database.providers';
import { users } from '@/users/users.schema';
// TODO: add commander
import { getTableName } from 'drizzle-orm';
import { exit } from 'process';
// TODO: use react-ink

const tables = [users];

console.log('Dropping the entire database');
db.delete(users);
// add more tables here

for (const table of tables) {
const name = getTableName(table);
console.log(`Dropping ${name}`);
await db.delete(users);
console.log(`Dropped ${name}`);
const tableResult = await db.select().from(table);
console.log(`${name} result: `, tableResult);
}

console.log('Database dropped');

exit(0);

0 comments on commit b8b6689

Please sign in to comment.