DB Least-Privilege Environment Contract
Goal
- Run application traffic with least-privilege credentials.
- Run schema migration operations with elevated migration-specific credentials.
Execution role
ELOQUENT_DB_ROLE=runtime(default): uses runtime credentials.ELOQUENT_DB_ROLE=migration: uses migration credentials.
What ELOQUENT_DB_ROLE means
ELOQUENT_DB_ROLE tells the ORM which credential set to prefer when it resolves a connection.
runtime: use this for your normal application process- HTTP requests
- Express controllers and services
- background jobs that read or write application data
- normal CRUD traffic
migration: use this only for schema-changing or migration-oriented jobsmigrate:runmigrate:freshmigrate:reset- CI migration stages
- controlled maintenance windows
- runtime credentials should be able to read and write app data
- migration credentials may need schema create, alter, or drop permissions
When to use it in development vs production
Use the same role model in every environment. The difference is the deployment target, not the meaning of the role.Local development app process
Local development migration command
Production app process
Production migration job
MySQL
Runtime
DB_RUNTIME_HOSTDB_RUNTIME_USERDB_RUNTIME_PASSWORDDB_RUNTIME_NAMEDB_RUNTIME_PORT
Migration
DB_MIGRATION_HOSTDB_MIGRATION_USERDB_MIGRATION_PASSWORDDB_MIGRATION_NAMEDB_MIGRATION_PORT
Test variants
DB_TEST_RUNTIME_*DB_TEST_MIGRATION_*
DB_HOST,DB_USER,DB_PASSWORD,DB_NAME,DB_PORTDB_TEST_HOST,DB_TEST_USER,DB_TEST_PASSWORD,DB_TEST_NAME,DB_TEST_PORT
PostgreSQL
Runtime
PG_RUNTIME_HOSTPG_RUNTIME_USERPG_RUNTIME_PASSWORDPG_RUNTIME_NAME(orPG_RUNTIME_DB_NAME)PG_RUNTIME_PORT
Migration
PG_MIGRATION_HOSTPG_MIGRATION_USERPG_MIGRATION_PASSWORDPG_MIGRATION_NAME(orPG_MIGRATION_DB_NAME)PG_MIGRATION_PORT
Test variants
PG_TEST_RUNTIME_*PG_TEST_MIGRATION_*
PG_HOST,PG_USER,PG_PASSWORD,PG_NAME(orPG_DB_NAME),PG_PORTPG_TEST_HOST,PG_TEST_USER,PG_TEST_PASSWORD,PG_TEST_NAME(orPG_TEST_DB_NAME),PG_TEST_PORT
SQLite
- Runtime path:
SQLITE_RUNTIME_PATH(fallbackSQLITE_PATH) - Migration path:
SQLITE_MIGRATION_PATH(fallbackSQLITE_PATH) - Tests:
SQLITE_TEST_RUNTIME_PATHSQLITE_TEST_MIGRATION_PATH
Recommended usage
- Runtime:
ELOQUENT_DB_ROLE=runtime - Migration jobs:
ELOQUENT_DB_ROLE=migration - CI test migrations: use
DB_TEST_MIGRATION_*andPG_TEST_MIGRATION_*withELOQUENT_DB_ROLE=migration
Minimum permission model
- Runtime users:
SELECT,INSERT,UPDATE,DELETEfor app tables. - Migration users: schema create/alter/drop only in target DB; avoid global admin privileges.