feat: add force sync option for db, don't alter by default

pull/4/head
Cameron Clough 2022-03-12 23:43:16 +00:00
parent f066ab53f6
commit c4625b77bd
No known key found for this signature in database
GPG Key ID: BFB3B74B026ED43F
2 changed files with 10 additions and 3 deletions

View File

@ -6,6 +6,7 @@ DB_USER=root
DB_PASS=root
DB_HOST=db # If using docker compose, this should match the container service name
DB_PORT=5432
DB_FORCE_SYNC=false # Whether or not to DROP all tables and recreate to match the current models
ALLOW_REGISTRATION=true
HTTP_INTERFACE=0.0.0.0
HTTP_PORT=3000

View File

@ -37,8 +37,14 @@ for (const modelDefiner of modelDefiners) {
modelDefiner(sequelize);
}
// Create tables if they don't exist
// Update columns to match if the table already exists
sequelize.sync({ alter: true });
/**
* Synchronise the database (create new tables) to match the models defined
* above.
*
* WARNING: If force is set, sequelize will delete columns and create new ones
* if their types have changed!
* Use sequelize-cli and migrations instead!
*/
sequelize.sync({ force: process.env.DB_FORCE_SYNC });
export default sequelize;