Files
signoz/cmd
Pandey db9a348a4e feat(cmd): add metastore migrate command (#11311)
* refactor(cmd): extract per-build sqlstore/sqlschema factory helpers

Move the build-specific composition of sqlstore and sqlschema provider
factories out of community/server.go and enterprise/server.go into
sibling metastore.go files. This deduplicates the wiring that will
otherwise be repeated in the upcoming metastore command, and keeps each
build's postgres opt-in expressed in exactly one place.

refs SigNoz/platform-pod#706

* feat(cmd): add metastore migrate sync up command

Introduce a 'metastore migrate sync up' cobra command that applies
SQL schema migrations as a standalone CLI step. Operators can now run
migrations to completion before bringing up the application, instead
of having them implicitly run on server startup.

The command accepts the same --config flag shape as 'server' so the
same YAML configuration files line up across both entrypoints. The
build-specific composition of sqlstore and sqlschema provider
factories is injected from cmd/{community,enterprise}/metastore.go.

refs SigNoz/platform-pod#706

* feat(cmd): register metastore command from both build mains

Wire RegisterMetastore into cmd/community/main.go and
cmd/enterprise/main.go so the new 'metastore migrate sync up'
subcommand is reachable from both binaries.

refs SigNoz/platform-pod#706

* feat(sqlmigrator): add Check method to report pending migrations

Check reports whether the database has any unapplied migrations
without applying them, intended for use by preflight/CI gates. It
returns nil when the database is up to date and a typed error
(ErrCodePendingSQLMigrations) listing the pending migration names
otherwise.

refs SigNoz/platform-pod#706

* refactor(cmd): split metastore registration from execution, add sync check

Mirror the server.go pattern: registerSync{Up,Check} only build the
cobra commands and parse flags; runSync{Up,Check} hold the actual
work and share a newSyncMigrator helper so the wiring of sqlstore,
sqlschema, telemetrystore and the SQL migrator lives in one place.

Adds the new 'metastore migrate sync check' subcommand, which calls
sqlmigrator.Check and exits non-zero when migrations are pending —
useful as a deployment preflight gate before bringing up the server.

refs SigNoz/platform-pod#706

* fix(sqlmigrator): drop Init from Check

Check should report state, not create the migration table. If the
migration table is missing, that's itself a signal that 'up' has not
been run.

refs SigNoz/platform-pod#706

* fix(sqlmigrator): use TypeUnexpected for pending migrations error

Pending migrations are a state mismatch, not bad caller input.
TypeUnexpected ('Generic mismatch of expectations') is the correct
category.

refs SigNoz/platform-pod#706

* fix(sqlmigrator): switch pending migrations error to TypeInternal

Pending migrations describe internal system state (the schema is
behind the target version), not bad caller input or a caller-visible
state mismatch. None of the existing types maps to a FAILED_PRECONDITION
equivalent, so TypeInternal is the closest fit.

refs SigNoz/platform-pod#706

* fix(sqlmigrator): use TypeNotFound for pending migrations error

refs SigNoz/platform-pod#706
2026-05-14 13:23:03 +00:00
..