Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduce DB migrations #593

Merged
merged 2 commits into from
Jan 15, 2025
Merged

feat: Introduce DB migrations #593

merged 2 commits into from
Jan 15, 2025

Conversation

aponcedeleonch
Copy link
Contributor

@aponcedeleonch aponcedeleonch commented Jan 15, 2025

Related: #583

We had been using a single DB schema that didn't change until now. This introduces migrations using alembic. To create a new migration one can use:

alembic revision -m "My migration"

That should generate an empty migration file that needs to be hand-filled. Specifically the upgrade method which will be the one executed when running the migration. See the existent migration 30d0144e1a50_init_db.py for a filled example.

"""My migration

Revision ID: <some_hash>
Revises: <previous_hash>
Create Date: YYYY-MM-DD HH:MM:SS.XXXXXX
"""
from alembic import op
import sqlalchemy as sa

revision = '<some_hash>'
down_revision = '<previous_hash>'
branch_labels = None
depends_on = None

def upgrade():
    pass

def downgrade():
    pass

Related: #583

We had been using a single DB schema that didn't change until now.
This introduces migrations using `alembic`. To create a new migration
one can use:
```sh
alembic revision -m "My migration"
```
That should generate an empty migration file that needs to be hand-filled.
Specifically the `upgrade` method which will be the one executed when
running the migration.
```python
"""My migration

Revision ID: <some_hash>
Revises: <previous_hash>
Create Date: YYYY-MM-DD HH:MM:SS.XXXXXX
"""
from alembic import op
import sqlalchemy as sa

revision = '<some_hash>'
down_revision = '<previous_hash>'
branch_labels = None
depends_on = None

def upgrade():
    pass

def downgrade():
    pass
```
JAORMX
JAORMX previously approved these changes Jan 15, 2025
alembic.ini Outdated Show resolved Hide resolved
migrations/versions/30d0144e1a50_init_db.py Show resolved Hide resolved
@aponcedeleonch aponcedeleonch merged commit 7593f72 into main Jan 15, 2025
2 checks passed
@aponcedeleonch aponcedeleonch deleted the db-migrations branch January 15, 2025 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants