miqro-sequelize
in early development not to use in production
this is a part of the miqro
module and provides sequelize integration.
- sequelize autogenerated configuration with Env vars.
- sequelize logger integration.
- sequelize-auto-migrations.
const {
Database
} = require("miqro-sequelize");
const {
Util
} = require("miqro-core");
Util.loadConfig();
const db = Database.getInstance();
// db.models[...].create({....})
migrations
to use sequelize-auto-migrations and seek for changes in model and create migrations.
miqro-sequelize makemigrations service.js
to apply migrations
miqro-sequelize migrate service.js
for making and running the migrations
miqro-sequelize automigrate service.js
configuration
default env vars needed
consider adding into your config/<NODE_ENV>.env
file.
LOG_LEVEL_Sequelize="error"
DB_NAME=
DB_HOST=
DB_PORT=
DB_USER=
DB_PASS=
DB_DIALECT=
DB_DIALECT_SSL=
DB_POOL_MAX=
DB_POOL_MIN=
DB_POOL_ACQUIRE=
DB_POOL_IDDLE=
DB_STORAGE=
# this will force sync the models when Database.start is called
DB_DROPTABLES=false
sequelize config
this file is autogenerated into config/db.js
that translates the Env vars to a sequelize config. To override this config just edit the file.
["DB_DIALECT_SSL", "DB_PORT", "DB_NAME", "DB_USER", "DB_PASS", "DB_HOST", "DB_DIALECT", "DB_POOL_MAX", "DB_POOL_MIN", "DB_POOL_ACQUIRE", "DB_POOL_IDDLE", "DB_STORAGE"].forEach((envName) => {
if (process.env[envName] === undefined) {
throw new Error(`Env variable [${envName}!] not defined`);
}
});
module.exports = {
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
host: process.env.DB_HOST,
dialect: process.env.DB_DIALECT,
port: process.env.DB_PORT,
dialectOptions: {
ssl: process.env.DB_DIALECT_SSL === "true"
},
pool: {
acquire: parseInt(process.env.DB_POOL_ACQUIRE, 10),
idle: parseInt(process.env.DB_POOL_IDDLE, 10),
max: parseInt(process.env.DB_POOL_MAX, 10),
min: parseInt(process.env.DB_POOL_MIN, 10)
},
storage: process.env.DB_STORAGE
};