Database Tools
The database tools manage database creation, schema migrations, privilege grants, and repair operations for all MATIH services across control plane and data plane PostgreSQL instances.
setup-databases.sh
Source: scripts/tools/setup-databases.sh
Creates databases and secrets for all services that require a PostgreSQL database.
Usage
./scripts/tools/setup-databases.shDatabase Definitions
| Service | Database | Namespace |
|---|---|---|
| config-service | config_db | matih-control-plane |
| notification-service | notification_db | matih-control-plane |
| billing-service | billing_db | matih-control-plane |
| audit-service | audit_db | matih-control-plane |
| iam-service | iam_db | matih-control-plane |
| tenant-service | tenant_db | matih-control-plane |
| observability-api | observability_db | matih-control-plane |
| ai-service | ai_db | matih-data-plane |
| ml-service | ml_db | matih-data-plane |
| data-plane-agent | agent_db | matih-data-plane |
| pipeline-service | pipeline_db | matih-data-plane |
| data-quality-service | quality_db | matih-data-plane |
Operations
- Read PostgreSQL admin password from Kubernetes secret
- For each service: create database if not exists
- For each service: create application user if not exists
- For each service: create Kubernetes secret with connection string
flyway-repair.sh
Source: scripts/tools/flyway-repair.sh
Repairs Flyway migration state for Java services that use Flyway for database schema management.
Usage
./scripts/tools/flyway-repair.sh <service-name>When to Use
| Scenario | Action |
|---|---|
| Failed migration left schema in inconsistent state | Run repair to fix checksum |
| Migration was manually applied | Run repair to mark as applied |
| Version conflict after branch merge | Run repair to recalculate checksums |
grant-db-schema-privileges.sh
Source: scripts/tools/grant-db-schema-privileges.sh
Grants schema-level privileges to service database users. Used when services need access to schemas created by other services.
Usage
./scripts/tools/grant-db-schema-privileges.shLibraries Used
| Library | Purpose |
|---|---|
core/logging.sh | Unified logging |
k8s/secrets.sh | Secret management |
Related Pages
- Stage 05: Infrastructure -- Database deployment
- Platform Status -- Cluster diagnostics