Caricash Nova Platform
Home
Home
  1. Internal
  • Default module
    • Clients
      • PBAC for Customer Authentication
      • Create Clients
    • Internal
      • Accounts, Transactioins and Ledger Implementatioin
      • Ensure real-time balance guarantees
      • Web App Scaffold
      • Database Migrations Guide
      • Microservices
      • Service Implementation
      • TO-DO
      • Authentication & Authorization
    • Customers
      • Onboarding
  • Release Schedule
    • Agency Operations
      • Agent APIs Specs
        • auth
          • POST /v1/agent/auth/login
          • POST /v1/agent/auth/logout
          • POST /v1/agent/auth/refresh
          • POST /v1/agent/auth/device-bind
          • POST /v1/agent/auth/otp/request
          • POST /v1/agent/auth/otp/verify
        • agent
          • GET /v1/agent/me
          • PATCH /v1/agent/me
          • GET /v1/agent/outlet
          • GET /v1/agent/capabilities
        • kyc
          • POST /v1/kyc/customers
          • POST /v1/kyc/customers/{customer_id}/upgrade
          • POST /v1/kyc/customers/{customer_id}/rekcy
          • GET /v1/kyc/customers/{customer_id}/status
        • transactions
          • POST /v1/txns/cashin
          • POST /v1/txns/cashout
          • POST /v1/txns/p2p/assist
          • GET /v1/txns/{txn_id}
          • POST /v1/txns/{txn_id}/reverse
        • wallets
          • GET /v1/wallets/{wallet_id}/balance
          • GET /v1/wallets/{wallet_id}/transactions
        • float
          • GET /v1/float
          • POST /v1/float/topup
          • POST /v1/float/redeem
          • GET /v1/float/instructions/{instruction_id}
        • commissions
          • GET /v1/agents/{agent_id}/commissions
          • POST /v1/agents/{agent_id}/commissions/payouts/preview
          • POST /v1/agents/{agent_id}/commissions/payouts/accept
        • disputes
          • POST /v1/disputes
          • GET /v1/disputes/{case_id}
          • POST /v1/disputes/{case_id}/attachments
        • reports
          • GET /v1/reports/eod
          • POST /v1/reports/eod/close
          • GET /v1/reports/txns
          • GET /v1/reports/float
        • content
          • GET /v1/announcements
        • training
          • GET /v1/training/courses
          • POST /v1/training/quizzes/{quiz_id}/submit
        • ussd
          • POST /v1/ussd/session
          • POST /v1/ussd/agent/menu
        • ops
          • GET /v1/health
      • Agent Scope
        • Agent Scope
    • Customer Operations
      • Customer Scope
        • Customer & Merchant Scope
    • Schemas
      • Agent Ops APIs
  • Nova Core Banking Service API
    • core
      • Create account
      • Get account
      • Get balances
      • Create posting (double-entry)
      • Reverse posting
      • Check limits
      • Generate statement
    • Schemas
      • Schemas
        • Amount
        • Account
        • BalanceSet
        • PostingEntry
        • Posting
        • Hold
        • LimitCheckResponse
        • SavingsProduct
        • OverdraftLine
        • StatementRequest
        • Error
Home
Home
  1. Internal

Database Migrations Guide

This guide explains how to organize, run, and automate database schema migrations across your dev, stg, and prod environments, using Bytebase and your CDK‑driven CI/CD pipeline.

1. Branch → Environment Mapping#

Git BranchCDK Context -c environmentBytebase Environment
developdevDev
stagingstgStg
mainprodProd
Your CI/CD workflow picks the branch name, sets both CDK and Bytebase contexts accordingly, then deploys infrastructure and applies migrations to the matching environment.

2. Directory Layout#

.
├── infra/                  # CDK application
│   ├── bytebase/           # BytebaseStack definition
│   ├── core/               # CoreStack definition
│   ├── migration/          # MigrationStack (if applicable)
│   └── api/                # ApiStack definition
└── db/
    └── migrations/         # SQL migration scripts, versioned
        ├── 001_create_users.sql
        ├── 002_add_email_idx.sql
        └── 003_create_posts.sql
db/migrations/ holds ordered, id‑prefixed .sql files.
Prefixes (001_, 002_, …) determine execution order.

3. Local Workflow#

1.
Write a migration
Create a new SQL file in db/migrations/, e.g.:
2.
Commit & push
Push your feature branch off develop.
3.
Apply to Dev locally
(requires the Bytebase CLI bb and a valid $BYTEBASE_TOKEN in your environment)
bb ddl apply \
  --project myapp \
  --environment dev \
  --file db/migrations/004_add_last_login.sql
4.
Verify
In Bytebase UI under Dev, confirm the change is applied and the forward/rollback scripts look correct.

4. CI/CD‑Driven Migrations#

We integrate Bytebase’s GitOps into GitHub Actions so that on each push to a branch:
develop → migrations imported/applied in Bytebase Dev
staging → migrations imported/applied in Bytebase Stg
main → migrations imported/applied in Bytebase Prod

.github/workflows/migrations.yml#


5. CDK CI/CD Integration#

Your existing CDK CI/CD pipeline now includes the bytebase stack:
Diff step runs:
for STACK in core migration api bytebase; do
  npx cdk diff nova-${ENV}-$STACK … --fail-on-destructive
done
Deploy step runs:
for STACK in core migration api bytebase; do
  npx cdk deploy nova-${ENV}-$STACK … --no-fail-on-empty-changeset
done
After deployment succeeds:
CloudFormation URLs for all four stacks are printed.
Bytebase service is live in the target environment.

6. Manual Promotion & Rollback#

Promote: merge develop → staging or staging → main.
Approval: Bytebase enforces your configured review policies (e.g. “2 approvers for Prod”).
Rollback: In Bytebase UI, find a Change Issue and click Rollback to execute the rollback script.

7. Validation & Auditing#

Audit trail: Bytebase logs every DDL change with timestamp, author, and SQL.
SQL Review: enforce linting and security policies via Bytebase’s built‑in SQL Review.
Drift Detection: Bytebase periodically scans for out‑of‑band schema changes and alerts when drift is detected.
Monitoring: check CloudWatch logs under the Bytebase log group for errors; verify EFS Infrequent Access transitions.
Modified at 2025-07-25 01:37:45
Previous
Web App Scaffold
Next
Microservices
Built with