Database Migrations in CDCM

Database Migrations in CDCM

Overview

CDCM uses database migrations to manage and version control changes to its MongoDB databases. These migrations ensure that your database schema and data remain consistent and up-to-date across deployments and version updates.

Migration System

Technology

CDCM implements database migrations using Mongock, a reliable migration tool specifically designed for MongoDB. This tool manages the execution and tracking of all database changes in a controlled and systematic way.

Migration Storage

  • All migration metadata is stored in a shared MongoDB database

  • The shared database name can be configured using the environment variable MONGO_SHARED_DATABASE

  • If not specified, the default database name is "cdcm"

  • The migration changelog tracks all executed migrations to prevent duplicate runs

Migration Behavior

Execution Process

  • Migrations run automatically during application startup

  • Progress is logged for monitoring and troubleshooting purposes

  • All CDCM spaces undergo migrations, including disabled spaces

  • Each migration is executed exactly once, tracked by the changelog

Zero-Downtime Deployment Support

CDCM migrations are designed to support zero-downtime deployments, which means:

  • All schema changes are backwards compatible

  • No special handling is required during Kubernetes rolling updates

  • Applications can operate normally while pods are being replaced one by one

  • Both old and new versions of the application can run simultaneously during the update process

Important Considerations

Changelog Management

The migration changelog is crucial for tracking executed migrations. Please note:

  • Deleting the changelog will cause migrations to re-run

  • Avoid manual modifications to the changelog

Best Practices

  1. Backup Strategy

    • Always maintain backups of your databases before running migrations

    • Include the shared database in your backup strategy

  2. Monitoring

    • Monitor migration logs during deployments

    • Verify successful completion of migrations before proceeding with application usage

  3. Deployment Planning

    • No special deployment procedures are required

    • Standard Kubernetes rolling updates are supported

    • No downtime is expected during migration execution