Ulf Gebhardt fcc99ab58e
refactor(backend): clean migrate scripts (#8317)
* clean migrate scripts

- refactor migrate:init
  - separate admin seed
  - separate categories seed
- rework backend README regarding the database
- remove `db:clean` command as its a duplicate of `db:reset`
- remove `__migrate` helper alias

* renamed clean.ts to reset.ts

* set indices & constrains in init function

* fix comment

* disable migrations touching indices

* remove obsolete comment

* always run init on kubernetes

* reset db with or without migrations

* lint fixes

* Refine 'README.md'

* Refine more 'README.md'

* fix lint

---------

Co-authored-by: Wolfgang Huß <wolle.huss@pjannto.com>
2025-04-10 09:52:49 +02:00

21 lines
692 B
TypeScript

/* eslint-disable n/no-process-exit */
import CONFIG from '@config/index'
import { cleanDatabase } from './factories'
if (CONFIG.PRODUCTION && !CONFIG.PRODUCTION_DB_CLEAN_ALLOW) {
throw new Error(`You cannot clean the database in a non-staging and real production environment!`)
}
;(async function () {
try {
await cleanDatabase()
console.log('Successfully deleted all nodes and relations!') // eslint-disable-line no-console
process.exit(0)
// eslint-disable-next-line no-catch-all/no-catch-all
} catch (err) {
console.log(`Error occurred deleting the nodes and relations (reset the db)\n\n${err}`) // eslint-disable-line no-console
process.exit(1)
}
})()