Problem
Currently, OSPOS relies on a pre-built database.sql file that must be manually executed to set up the database schema. This creates several issues:
- Docker complexity: Requires a separate
sqlscript container to mount and execute the SQL file
- Manual installation step: Users must manually import
database.sql before the app works
- Maintenance burden:
database.sql is generated from tables.sql + constraints.sql via a gulp task, adding build complexity
- Migration conflicts: When tests or fresh installs run migrations on top of
database.sql, the migration history table doesn't reflect that migrations have already been applied, causing Duplicate column errors
Solution
Convert database.sql into an initial migration that:
- Runs
tables.sql + constraints.sql as the first migration
- Only executes on fresh/empty databases - skips if tables already exist (preserves existing installs)
- Marks itself as complete so subsequent migrations don't re-run
Changes Made
New Initial Migration
- Created
app/Database/Migrations/20170501000000_initial_schema.php
- Loads
app/Database/Migrations/sqlscripts/initial_schema.sql (tables.sql + constraints.sql combined)
- Checks if tables exist before running - skips on existing installations
- Marks migration as complete so it won't run again
Docker Simplification
- Removed
sqlscript container from docker-compose.yml and docker/docker-mysql.yml
- Removed
database.sql volume mount from docker-compose.dev.yml
- MySQL containers now only need to create empty database with credentials
Build Process
- Removed
build-database gulp task from gulpfile.js
- Database schema is now version-controlled via migrations, not generated
CI/CD
- Removed
Build database.sql step from .github/workflows/phpunit.yml
- Removed
Initialize database step from .github/workflows/build-release.yml
- Tests now rely on migrations to set up schema
Documentation
- Updated
INSTALL.md to reflect automatic schema creation via migrations
- Removed manual
Execute the file app/Database/database.sql step
Benefits
- One-step setup: Just create empty database, migrations handle the rest
- Docker simplicity: No separate SQL container needed
- Better migration support: Existing installs upgrade normally, fresh installs get full schema
- No build-time SQL generation: Schema is versioned in source files
- Consistent testing: CI tests use same migration path as production
Migration Path
- Fresh installs: Initial migration creates full schema, subsequent migrations are no-ops
- Existing installations: Migration sees tables exist, skips initial schema load, continues normally
- Upgrades: No change - existing migrations continue to work
Problem
Currently, OSPOS relies on a pre-built
database.sqlfile that must be manually executed to set up the database schema. This creates several issues:sqlscriptcontainer to mount and execute the SQL filedatabase.sqlbefore the app worksdatabase.sqlis generated fromtables.sql+constraints.sqlvia a gulp task, adding build complexitydatabase.sql, the migration history table doesn't reflect that migrations have already been applied, causingDuplicate columnerrorsSolution
Convert
database.sqlinto an initial migration that:tables.sql+constraints.sqlas the first migrationChanges Made
New Initial Migration
app/Database/Migrations/20170501000000_initial_schema.phpapp/Database/Migrations/sqlscripts/initial_schema.sql(tables.sql + constraints.sql combined)Docker Simplification
sqlscriptcontainer fromdocker-compose.ymlanddocker/docker-mysql.ymldatabase.sqlvolume mount fromdocker-compose.dev.ymlBuild Process
build-databasegulp task fromgulpfile.jsCI/CD
Build database.sqlstep from.github/workflows/phpunit.ymlInitialize databasestep from.github/workflows/build-release.ymlDocumentation
INSTALL.mdto reflect automatic schema creation via migrationsExecute the file app/Database/database.sqlstepBenefits
Migration Path