Skip to content

Support explicit repository migration dependencies #95

Description

@mishankov

Problem

Database migrations are collected from repositories stored in a Go map. Map iteration order is nondeterministic, so migrations from different repositories cannot safely reference one another. A domain that owns a foreign key cannot guarantee that the referenced domain table already exists. Registration order currently does not express or enforce this dependency.

Proposed direction

Allow repositories or domains to declare migration dependencies, for example:

app.RegisterDomain("task", "main", taskDomain, application.DependsOn("project"))

Before applying migrations, build a dependency graph and topologically sort repositories. Independent repositories should still have a deterministic order.

Acceptance criteria

  • A repository/domain can explicitly depend on one or more registered repositories/domains.
  • Migrations are applied in topological dependency order.
  • Unknown dependencies and dependency cycles fail before any product migration is applied, with a useful error.
  • Independent repositories use a stable deterministic order.
  • Rollback of migrations applied in the current run happens in reverse application order.
  • Tests cover a cross-repository foreign key, independent repositories, an unknown dependency, and a cycle.
  • Existing registrations without dependencies remain source-compatible.

Motivation

Todai needs tasks.project_id to reference projects.id. Without ordered cross-repository migrations, the application must temporarily omit that database invariant and enforce project ownership/existence only in application SQL.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions