Skip to content

Instantly share code, notes, and snippets.

@franTarkenton
Last active August 31, 2022 20:01
Show Gist options
  • Save franTarkenton/f2e593d7af6ecf9ff93953cdedf16fbe to your computer and use it in GitHub Desktop.
Save franTarkenton/f2e593d7af6ecf9ff93953cdedf16fbe to your computer and use it in GitHub Desktop.
Describing Database Migrations

FAM API - Database Migrations

  • What is the source of Database Truth - ORM Model, Datamodel (ER Studio), Flyway

Background


API Development: Fastapi


Flyway as Lambda for database migrations in RDS

  • pattern exists, easy to implement
  • Flyway uses plain SQL for migrations - easy to generate
  • ER Studio Datamodel can easily create flyway migrations

ISSUE:

  • Fastapi is configuration driven...
  • we already have an existing data model
  • development wants to be able to support datamodel changes while we work, using the ORM Model.
  • Existing ORM model was generated from ER Studio output /
  • How do we get datamodel changes deployed.

Using Existing Datamodel and migrations - cleanup

  • objective 1:1 relationship between alembic migrations / flyway migrations
  • Run flyway migration on temporary database
  • Use sqlacodegen to generate a ORM model
  • Use Alembic to generate an alembic database migration

Moving Forward - Datamodel changes implemented through ORM model

  • ORM becomes source of truth
  • before push/pr
    • generate an alembic migration
    • generate a flyway migration
    • THEN PUSH

Future

  • automate generation of alembic migrations and flyway migrations in pipeline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment