🧱 Database Migration
Overview
This document describes the steps required to migrate an existing dataset from a database or revert a migration. Migrations should take place whenever the persistent data schema changes, to avoid errors and data loss.
Format
- Migrations should be create inside
scripts/migrations
- Migrations should extend
BaseMigration
and implementup
anddown
methods - Each migration should be documented using module docstrings
- Each migration file should be named following this format: Example:
Requirements
Backend/
should be the root folder- Backend setup must be done before running any script
➡️ Migrate (Up)
This procedure will apply a migration on a dataset.
- Go to Backend/
- Create a migration file that extends
BaseMigration
class underapp/scripts/migrations
- Write module docs at the top of the file describing what the migration does
- Add the following entrypoint:
- Run
python -m app.scripts.migrations.migration_file db_uri up
. Example:
🔙 Revert Migration (Down)
This procedure will revert a migration on a dataset.
- Follow the same steps as for doing a migration but instead execte this code: