config files and scripts for database migration system
This commit is contained in:
7
backend/.sequelizerc
Normal file
7
backend/.sequelizerc
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
'config': path.resolve('config', 'database.js'),
|
||||||
|
'migrations-path': path.resolve('migrations'),
|
||||||
|
'models-path': path.resolve('models'),
|
||||||
|
};
|
||||||
@@ -1,21 +1,62 @@
|
|||||||
const { Sequelize } = require('sequelize');
|
const { Sequelize } = require("sequelize");
|
||||||
|
|
||||||
const sequelize = new Sequelize(
|
// Load environment variables based on NODE_ENV
|
||||||
process.env.DB_NAME,
|
// This ensures variables are available for both CLI and programmatic usage
|
||||||
process.env.DB_USER,
|
if (!process.env.DB_NAME && process.env.NODE_ENV) {
|
||||||
process.env.DB_PASSWORD,
|
const dotenv = require("dotenv");
|
||||||
{
|
const envFile = `.env.${process.env.NODE_ENV}`;
|
||||||
|
const result = dotenv.config({ path: envFile });
|
||||||
|
if (result.error && process.env.NODE_ENV !== "production") {
|
||||||
|
console.warn(
|
||||||
|
`Warning: Could not load ${envFile}, using existing environment variables`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Database configuration object
|
||||||
|
// Used by both Sequelize CLI and programmatic initialization
|
||||||
|
const dbConfig = {
|
||||||
|
username: process.env.DB_USER,
|
||||||
|
password: process.env.DB_PASSWORD,
|
||||||
|
database: process.env.DB_NAME,
|
||||||
host: process.env.DB_HOST,
|
host: process.env.DB_HOST,
|
||||||
port: process.env.DB_PORT,
|
port: process.env.DB_PORT || 5432,
|
||||||
dialect: 'postgres',
|
dialect: "postgres",
|
||||||
logging: false,
|
logging: false,
|
||||||
pool: {
|
pool: {
|
||||||
max: 5,
|
max: 5,
|
||||||
min: 0,
|
min: 0,
|
||||||
acquire: 30000,
|
acquire: 10000,
|
||||||
idle: 10000
|
idle: 10000,
|
||||||
}
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Configuration for Sequelize CLI (supports multiple environments)
|
||||||
|
// All environments use the same configuration from environment variables
|
||||||
|
const cliConfig = {
|
||||||
|
development: dbConfig,
|
||||||
|
dev: dbConfig,
|
||||||
|
test: dbConfig,
|
||||||
|
qa: dbConfig,
|
||||||
|
production: dbConfig,
|
||||||
|
prod: dbConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create Sequelize instance for programmatic use
|
||||||
|
const sequelize = new Sequelize(
|
||||||
|
dbConfig.database,
|
||||||
|
dbConfig.username,
|
||||||
|
dbConfig.password,
|
||||||
|
{
|
||||||
|
host: dbConfig.host,
|
||||||
|
port: dbConfig.port,
|
||||||
|
dialect: dbConfig.dialect,
|
||||||
|
logging: dbConfig.logging,
|
||||||
|
pool: dbConfig.pool,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Export the sequelize instance as default (for backward compatibility)
|
||||||
|
// Also export all environment configs for Sequelize CLI
|
||||||
module.exports = sequelize;
|
module.exports = sequelize;
|
||||||
|
Object.assign(module.exports, cliConfig);
|
||||||
|
|||||||
@@ -16,6 +16,12 @@
|
|||||||
"test:unit": "NODE_ENV=test jest tests/unit",
|
"test:unit": "NODE_ENV=test jest tests/unit",
|
||||||
"test:integration": "NODE_ENV=test jest tests/integration",
|
"test:integration": "NODE_ENV=test jest tests/integration",
|
||||||
"test:ci": "NODE_ENV=test jest --ci --coverage --maxWorkers=2",
|
"test:ci": "NODE_ENV=test jest --ci --coverage --maxWorkers=2",
|
||||||
|
"db:migrate": "sequelize-cli db:migrate",
|
||||||
|
"db:migrate:undo": "sequelize-cli db:migrate:undo",
|
||||||
|
"db:migrate:undo:all": "sequelize-cli db:migrate:undo:all",
|
||||||
|
"db:migrate:status": "sequelize-cli db:migrate:status",
|
||||||
|
"db:create": "sequelize-cli db:create",
|
||||||
|
"test:migrations": "node scripts/test-migrations.js",
|
||||||
"alpha:add": "NODE_ENV=dev node scripts/manageAlphaInvitations.js add",
|
"alpha:add": "NODE_ENV=dev node scripts/manageAlphaInvitations.js add",
|
||||||
"alpha:list": "NODE_ENV=dev node scripts/manageAlphaInvitations.js list",
|
"alpha:list": "NODE_ENV=dev node scripts/manageAlphaInvitations.js list",
|
||||||
"alpha:revoke": "NODE_ENV=dev node scripts/manageAlphaInvitations.js revoke",
|
"alpha:revoke": "NODE_ENV=dev node scripts/manageAlphaInvitations.js revoke",
|
||||||
|
|||||||
Reference in New Issue
Block a user