mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
enforce config database
This commit is contained in:
parent
677581b76e
commit
c9177bbce3
@ -1,3 +1,5 @@
|
|||||||
|
CONFIG_VERSION=v1.2022-03-18
|
||||||
|
|
||||||
DB_HOST=localhost
|
DB_HOST=localhost
|
||||||
DB_PORT=3306
|
DB_PORT=3306
|
||||||
DB_USER=root
|
DB_USER=root
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
CONFIG_VERSION=$DATABASE_CONFIG_VERSION
|
||||||
|
|
||||||
DB_HOST=localhost
|
DB_HOST=localhost
|
||||||
DB_PORT=3306
|
DB_PORT=3306
|
||||||
DB_USER=$DB_USER
|
DB_USER=$DB_USER
|
||||||
|
|||||||
@ -3,6 +3,14 @@
|
|||||||
import dotenv from 'dotenv'
|
import dotenv from 'dotenv'
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
||||||
|
const constants = {
|
||||||
|
CONFIG_VERSION: {
|
||||||
|
DEFAULT: 'DEFAULT',
|
||||||
|
EXPECTED: 'v1.2022-03-18',
|
||||||
|
CURRENT: '',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
const database = {
|
const database = {
|
||||||
DB_HOST: process.env.DB_HOST || 'localhost',
|
DB_HOST: process.env.DB_HOST || 'localhost',
|
||||||
DB_PORT: process.env.DB_PORT ? parseInt(process.env.DB_PORT) : 3306,
|
DB_PORT: process.env.DB_PORT ? parseInt(process.env.DB_PORT) : 3306,
|
||||||
@ -15,6 +23,18 @@ const migrations = {
|
|||||||
MIGRATIONS_TABLE: process.env.MIGRATIONS_TABLE || 'migrations',
|
MIGRATIONS_TABLE: process.env.MIGRATIONS_TABLE || 'migrations',
|
||||||
}
|
}
|
||||||
|
|
||||||
const CONFIG = { ...database, ...migrations }
|
// Check config version
|
||||||
|
constants.CONFIG_VERSION.CURRENT = process.env.CONFIG_VERSION || constants.CONFIG_VERSION.DEFAULT
|
||||||
|
if (
|
||||||
|
![constants.CONFIG_VERSION.EXPECTED, constants.CONFIG_VERSION.DEFAULT].includes(
|
||||||
|
constants.CONFIG_VERSION.CURRENT,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
`Fatal: Config Version incorrect - expected "${constants.CONFIG_VERSION.EXPECTED}" or "${constants.CONFIG_VERSION.DEFAULT}", but found "${constants.CONFIG_VERSION.CURRENT}"`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const CONFIG = { ...constants, ...database, ...migrations }
|
||||||
|
|
||||||
export default CONFIG
|
export default CONFIG
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user