Simpler.Grants.gov Public Wiki
Grants.govSimpler.Grants.govGitHubDiscourse
  • 👋Welcome
  • GET INVOLVED
    • Why open source?
    • How to contribute code
    • How to file issues
      • Report a bug
      • Request a feature
      • Report a security vulnerability
    • Community guidelines
      • Code of Conduct
      • Reporting and removing content
      • Incident response protocol
    • Community events
      • Fall 2024 Coding Challenge
        • Event Submissions & Winners
      • Spring 2025 Collaborative Coding Challenge
        • Event Submissions & Winners
    • Communication channels
  • Product
    • Roadmap
    • Deliverables
      • 🏁Static site soft launch
      • 🏁Static site public launch
      • 🏁GET Opportunities
      • 🏁Open source onboarding
      • 🏁Co-Design Group planning
    • Decisions
      • ADR Template
      • ADRs
        • Dedicated Forum for Simpler.Grants.gov Community
        • Recording Architecture Decisions
        • Task Runner for the CI / CD Pipeline
        • API Language
        • Use Figma for design prototyping
        • ADR: Chat
        • DB Choices
        • API Framework and Libraries
        • Back-end Code Quality Tools
        • Front-end Language
        • Communications Tooling: Wiki Platform
        • Use Mural for design diagrams and whiteboarding
        • Ticket Tracking
        • Front-end Framework
        • Front-end Code Quality Tools
        • Front-end Testing & Coverage
        • Backend API Type
        • Front-end Testing & Coverage
        • Deployment Strategy
        • Use U.S. Web Design System for components and utility classes
        • FE server rendering
        • Use NPM over Yarn Architectural Decision Records
        • U.S. Web Design System in React
        • Communications Tooling: Video Conferencing
        • Back-end Production Server
        • Communications Tooling: Analytics Platform
        • Commit and Branch Conventions and Release Workflow
        • Cloud Platform to Host the Project
        • Infrastructure as Code Tool
        • Data Replication Strategy & Tool
        • HHS Communications Site
        • Communications Tooling: Email Marketing
        • Communications Tooling: Listserv
        • Use Ethnio for design research
        • Uptime Monitoring
        • Database Migrations
        • 30k ft deliverable reporting strategy
        • Public measurement dashboard architecture
        • Method and technology for "Contact Us" CTA
        • E2E / Integration Testing Framework
        • Logging and Monitoring Platform
        • Dashboard Data Storage
        • Dashboard Data Tool
        • Search Engine
        • Document Storage
        • Document Sharing
        • Internal Wiki ADR
        • Shared Team Calendar Platform
        • Cross-Program Team Health Survey Tool
        • Adding Slack Users to SimplerGrants Slack Workspace
        • Repo organization
        • Internal knowledge management
        • Migrate Existing API Consumers
      • Infra
        • Use markdown architectural decision records
        • CI/CD interface
        • Use custom implementation of GitHub OIDC
        • Manage ECR in prod account module
        • Separate terraform backend configs into separate config files
        • Database module design
        • Provision database users with serverless function
        • Database migration architecture
        • Consolidate infra config from tfvars files into config module
        • Environment use cases
        • Production networking long term state
    • Analytics
      • Open source community metrics
      • API metrics
  • DESIGN & RESEARCH
    • Brand guidelines
      • Logo
      • Colors
      • Grid and composition
      • Typography
      • Iconography
      • Photos and illustrations
    • Content guidelines
      • Voice and tone
    • User research
      • Grants.gov archetypes
  • REFERENCES
    • Glossary
  • How to edit the wiki
Powered by GitBook
On this page
  • Context and Problem Statement
  • Decision Drivers
  • Options Considered
  • Decision Outcome
  • Positive Consequences
  • Negative Consequences
  • Pros and Cons of the Options
  • Alembic
  • AWS Database Migration Service
  • Django
  • Flyway
  • Liquibase

Was this helpful?

Edit on GitHub
  1. Product
  2. Decisions
  3. ADRs

Database Migrations

PreviousUptime MonitoringNext30k ft deliverable reporting strategy

Last updated 28 days ago

Was this helpful?

  • Status: Accepted

  • Last Modified: 2023-12-06

  • Related Issue:

  • Deciders: Lucas, Aaron, Billy, Sammy, Michael

  • Tags: Database, Backend

Context and Problem Statement

We need a tool that can help manage the schema of our database, as well as make updates to the schema as we add more to it.

NOTE: At the time of writing this, the API already uses Alembic, and this document is more to describe why we use it, rather than to make a decision.

Decision Drivers

  • Ease of use: Creating new migrations should be easy and intuitive

  • Maintenance effort: The tool should be easy to maintain as we add more to our database schema

  • Minimizing risk: The tool should gracefully handle migration failures

  • Cost: This tool should be cost effective

Options Considered

  • Alembic

  • AWS Database Migration Service

  • Django

  • Flyway

  • Liquibase

Decision Outcome

Chosen option: Alembic, because it handles our known use cases, has minimal overhead, and is the go-to framework for the ORM we also use.

Any other option requires us to create migrations through a process that requires significantly more work, either by manually making those files, or generating them with another tool. Alembic just reads the ORM models we already are writing and generates the migrations for us.

Positive Consequences

  • Ease of use: Migrations are generated directly from our SQLAlchemy ORM models

  • Maintenance effort: Migrations are generally uneventful to add, and just require running a single command to automatically generate

  • Minimizing risk: Migrations are run in transactions, if any error occurs, they automatically roll back. If an issue occurs after the migration happens, a downgrade is generated for you as well to revert.

  • Cost: Alembic is open source and free

Negative Consequences

  • Maintenance effort: Some advanced migration features may be more difficult to execute

Pros and Cons of the Options

Alembic

The migration files Alembic generates each receive a unique identifier, and the only information it needs to track is the current one. When you run the database migrations, it finds the file with the current id, and sees if any migration is derived from it, similar to a linked list. If more than one file references the same migration (most commonly caused by two developers merging changes in quick succession), then Alembic will error when attempting to run the migrations, requiring someone to create a new merge migration and define the order.

When Alembic migrations fail, they do not commit any changes to the database.

  • Pros

    • Built specifically to work with SQLAlchemy, the ORM layer that we already use

    • Capable of automatically generating migrations for most common schema changes from our SQLAlchemy models, making most migrations zero effort

    • Migrations are generated locally by a developer, and can be run against your local database to test the changes

    • No cost, is an open source extension of SQLAlchemy which is also free

  • Cons

    • There are some scenarios where Alembic cannot detect database changes like renaming a table or column - instead a developer would need to manually modify the migration to do the rename

AWS Database Migration Service

  • Pros

    • We already will be using DMS to copy data from the existing Oracle DB to our new Postgres DB which will require schema configuration to work

  • Cons

    • Eventually we will no longer be copying data from the legacy Oracle DB to our DB, at which point we'd need to find a new migration approach

    • Local development would not be able to setup a database using AWS DMS, local testing of schema changes would require a separate local-only process

Django

  • Pros

    • Thoroughly integrated with the Django framework with lots of customization possible

  • Cons

Flyway

  • Pros

  • Cons

    • Creating new migrations requires using their Flyway Desktop application to generate the migration files which is another tool we would need to learn

    • Has cost tiers depending on your organization size

Liquibase

  • Pros

    • Allows you to configure your migrations in XML, JSON, or YAML, not just raw SQL

  • Cons

    • While it has a free open-source version, many key features like rollbacks look to be locked behind the Pro version

is a database migration tool that can generate database migrations from our schema. It is capable of most common database modifications including table, column, and index additions.

See for some details on how we use Alembic in this environment

Certain repeatable migrations (like updating functions, views, or triggers) aren't detected by default, but a exists which can detect and automate this for you.

(DMS) is a tool for copying and converting your database.

AWS DMS is opinionated on database types in ways that conflict with Postgres documentation. For example, DMS largely prefers using VARCHAR for any string column despite saying TEXT and VARCHAR are the same performance-wise. While you can convert with AWS DMS, this adds additional overhead to a very common column type.

The Django framework comes with its own .

Provides a way to as they build up over time

We would need to switch our API stack to use Django, see for further details on this decision process

is a Java-based application that manages running SQL migrations.

a variety of deployment approaches, and version controls

is Java-based application that manages running SQL migrations.

Thorough

#779
Alembic
SQLAlchemy ORM
automatically detecting
database-management.md
library
AWS Database Migration Service
Postgres docs
migration process
squash migrations
API Framework
Flyway
Supports
Liquibase
documentation