diff --git a/.env.sample b/.env.sample index 1f488fa..5bb67a4 100644 --- a/.env.sample +++ b/.env.sample @@ -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 diff --git a/models/index.model.js b/models/index.model.js index 1a0e8f0..7360904 100644 --- a/models/index.model.js +++ b/models/index.model.js @@ -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;