Summary
Replace the single ApiTypes.MigrationDBHandle with two separate handles that make the migration track ownership explicit:
ApiTypes.ProjectMigrationDBHandle — used by goose.RunProjectMigrations for project-level schema changes
ApiTypes.SharedMigrationDBHandle — used by goose.RunSharedMigrations for shared-library schema changes
Background
The system has three goose migration tracks:
| Track |
Migrator |
Location |
| Project |
goose.ProjectMigrator |
<project>/server/migrations/ |
| Shared |
goose.SharedMigrator |
shared/migrations/ |
| AutoTester |
goose.AutoTesterMigrator |
<project>/server/migrations/autotester/ |
Previously, a single MigrationDBHandle was connecting to a separate PG_DB_NAME_MIGRATION database. This was incorrect — project tables and shared tables both live in the same database (ProjectDBHandle). Both migration tracks should therefore run against the project DB, differentiated only by their goose version-tracking table names.
Changes Made
shared/go/api/ApiTypes/ApiTypes.go
- Replaced global
var MigrationDBHandle *sql.DB with var ProjectMigrationDBHandle *sql.DB and var SharedMigrationDBHandle *sql.DB
- In
DatabaseConfig struct: removed MigrationDBHandle *sql.DB and MigrationDBName string; added ProjectMigrationDBHandle *sql.DB and SharedMigrationDBHandle *sql.DB
shared/go/api/ApiUtils/ApiUtils.go
- Removed the separate migration DB connection (no longer opens a connection to
PG_DB_NAME_MIGRATION)
- Both
ProjectMigrationDBHandle and SharedMigrationDBHandle are now assigned to ProjectDBHandle at initialisation time
- Removed
PG_DB_NAME_MIGRATION env var requirement and related validations
- Updated
SetConfig to populate both new handles
shared/go/api/databaseutil/databaseutil.go
- Removed
MigrationDBHandle.Close() calls from CloseDatabase (closing ProjectDBHandle is sufficient since the migration handles share the same pointer)
Callers updated
ChenWeb/server/cmd/deepdoc/main.go
ChenWeb/server/cmd/autotester/main.go
tax/server/cmd/autotester/main.go
shared/go/cmd/autotester/main.go
ChenWeb/server/cmd/config/config.go
Environment Variable Removed
PG_DB_NAME_MIGRATION is no longer required. Any .env files referencing this variable can be cleaned up.
Summary
Replace the single
ApiTypes.MigrationDBHandlewith two separate handles that make the migration track ownership explicit:ApiTypes.ProjectMigrationDBHandle— used bygoose.RunProjectMigrationsfor project-level schema changesApiTypes.SharedMigrationDBHandle— used bygoose.RunSharedMigrationsfor shared-library schema changesBackground
The system has three goose migration tracks:
goose.ProjectMigrator<project>/server/migrations/goose.SharedMigratorshared/migrations/goose.AutoTesterMigrator<project>/server/migrations/autotester/Previously, a single
MigrationDBHandlewas connecting to a separatePG_DB_NAME_MIGRATIONdatabase. This was incorrect — project tables and shared tables both live in the same database (ProjectDBHandle). Both migration tracks should therefore run against the project DB, differentiated only by their goose version-tracking table names.Changes Made
shared/go/api/ApiTypes/ApiTypes.govar MigrationDBHandle *sql.DBwithvar ProjectMigrationDBHandle *sql.DBandvar SharedMigrationDBHandle *sql.DBDatabaseConfigstruct: removedMigrationDBHandle *sql.DBandMigrationDBName string; addedProjectMigrationDBHandle *sql.DBandSharedMigrationDBHandle *sql.DBshared/go/api/ApiUtils/ApiUtils.goPG_DB_NAME_MIGRATION)ProjectMigrationDBHandleandSharedMigrationDBHandleare now assigned toProjectDBHandleat initialisation timePG_DB_NAME_MIGRATIONenv var requirement and related validationsSetConfigto populate both new handlesshared/go/api/databaseutil/databaseutil.goMigrationDBHandle.Close()calls fromCloseDatabase(closingProjectDBHandleis sufficient since the migration handles share the same pointer)Callers updated
ChenWeb/server/cmd/deepdoc/main.goChenWeb/server/cmd/autotester/main.gotax/server/cmd/autotester/main.goshared/go/cmd/autotester/main.goChenWeb/server/cmd/config/config.goEnvironment Variable Removed
PG_DB_NAME_MIGRATIONis no longer required. Any.envfiles referencing this variable can be cleaned up.