GhaylStackDocumentationv1.0.2
العربيةWebsite
Operations

Operations

Database migrations

Apply schema changes through DbMigrator and move existing data with an explicit recovery plan.

Separate migration from API startup

DbMigrator is a one-shot console application. It loads the tenant catalog first, then visits selected tenants and asks the registered initializers to migrate or seed their module data. The API does not replace this deployment step.

Configure DatabaseOptions__ConnectionString for the intended database and an account with the required DDL permissions. DatabaseOptions__Provider is POSTGRESQL; the source migration assembly is GhaylStack.Migrations.PostgreSQL. Generated applications use their own renamed assembly. Verify the connected database and role printed in the migrator log before proceeding.

Select the intended operation

Command or option Behavior
apply Migrate catalog, then selected tenants
apply --seed Also invoke per-tenant seeding
apply --tenant acme Restrict the tenant pass; catalog processing still occurs
apply --catalog-only Skip the per-tenant pass
seed Run per-tenant seeds after catalog handling
seed-demo Development-only sample tenants and content
list-pending Inspect catalog migrations without applying them

The current list-pending implementation lists pending catalog migrations and prints a general note for each tenant; it does not enumerate every module's pending migrations. It expects a usable initialized catalog for tenant reads. Do not treat it as a complete schema-diff report for a brand-new empty database.

Apply and verify

With the target configured, run from the source root:

sh
dotnet run --project src/Host/GhaylStack.DbMigrator -- apply
dotnet run --project src/Host/GhaylStack.DbMigrator -- list-pending

For an initialized installation, inspect list-pending before the change as well. The migrator waits for PostgreSQL and takes a PostgreSQL advisory lock to serialize migration runs against its lock target. Success exits 0 and prints a completion message; failures exit 1 with an exception. A tenant filter matching no records is reported in the log, so inspect it even when the command exits successfully.

Verify module schema changes and relevant application operations afterwards. A clear catalog listing alone does not establish that every business workflow works.

Create a migration during development

After changing a model, restore the pinned EF tool and build before generating a migration. This example names a new Catalog migration; use a name describing your actual change:

sh
dotnet tool restore
dotnet build src/GhaylStack.slnx -c Release
dotnet ef migrations add AddProductReference --project src/Host/GhaylStack.Migrations.PostgreSQL --startup-project src/Host/GhaylStack.Api --context CatalogDbContext --output-dir Catalog

Review generated operations and the snapshot before applying to a disposable database. Test the affected feature and tenant boundaries. See persistence for data-model rules.

Move an existing installation

A new AppHost prefix creates new volumes. It does not migrate old data. Record database versions, roles, extensions, encoding and ICU locale; stop writes and create a restorable logical backup, including associated object storage and key material.

Restore into a separate compatible target. Do not mount an older major version's data directory into PostgreSQL 18.7. Check ordering and ranked chat results, then run migrations without demo seeding. Verify tenant counts, permissions and attachments before moving traffic. Application rollback does not automatically reverse schema changes or reconcile writes made after cutover.

Sources

Migrator implementation, command parser, EF tool version and database image guidance.

View MarkdownBack to top

Search documentation

Use ↑ ↓ to move, Enter to open and Esc to close.