Skip to content

Refactor: Split MigrationDBHandle into ProjectMigrationDBHandle and SharedMigrationDBHandle #15

@chendingplano

Description

@chendingplano

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions