-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c89ed71
commit 205eef2
Showing
3 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import postgres from 'postgres'; | ||
|
||
// Configure your PostgreSQL connection | ||
const sql = postgres(process.env.DB_URL!); | ||
|
||
async function cleanupDatabase() { | ||
try { | ||
// Delete old records | ||
const deleteResult = await sql` | ||
DELETE FROM items | ||
WHERE timestamp < CURRENT_DATE - INTERVAL '30 days' | ||
`; | ||
console.log(`Deleted ${deleteResult.count} rows`); | ||
|
||
// VACUUM FULL ANALYZE | ||
console.log('Starting VACUUM FULL ANALYZE...'); | ||
await sql.unsafe('VACUUM FULL ANALYZE items'); | ||
console.log('VACUUM FULL ANALYZE completed'); | ||
|
||
// REINDEX | ||
console.log('Starting REINDEX...'); | ||
await sql.unsafe('REINDEX TABLE items'); | ||
console.log('REINDEX completed'); | ||
|
||
console.log('Database cleanup completed successfully'); | ||
} catch (err) { | ||
console.error('Error during database cleanup:', err); | ||
} finally { | ||
await sql.end(); | ||
} | ||
} | ||
|
||
// Run the cleanup function | ||
cleanupDatabase(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.