-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrop-database.js
More file actions
33 lines (26 loc) · 849 Bytes
/
drop-database.js
File metadata and controls
33 lines (26 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Drop entire database and recreate fresh
import { Pool } from 'pg'
import 'dotenv/config'
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
})
async function dropDatabase() {
throw new Error('You can\'t delete the production database')
try {
console.log('🗑️ Dropping entire production database...')
// Drop all tables with CASCADE to handle foreign key dependencies
await pool.query(`
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
`)
console.log('✅ Database completely cleared!')
console.log('🎉 Ready for fresh migration - run: npx drizzle-kit push')
console.log('')
console.log('All tables will be created fresh.')
} catch (error) {
console.error('Error dropping database:', error)
} finally {
await pool.end()
}
}
dropDatabase()