-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-4: Introduce Alembic for database migrations
- Loading branch information
1 parent
025b13a
commit 63584cc
Showing
6 changed files
with
73 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[alembic] | ||
script_location = schemes:migrations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from alembic import context | ||
|
||
connection = context.config.attributes["connection"] | ||
context.configure(connection=connection, target_metadata=None) | ||
|
||
with context.begin_transaction(): | ||
context.run_migrations() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""${message} | ||
|
||
Revision ID: ${up_revision} | ||
Revises: ${down_revision | comma,n} | ||
Create Date: ${create_date} | ||
|
||
""" | ||
from typing import Sequence, Union | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
revision: str = ${repr(up_revision).replace("'", '"')} | ||
down_revision: Union[str, None] = ${repr(down_revision).replace("'", '"')} | ||
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels).replace("'", '"')} | ||
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on).replace("'", '"')} | ||
|
||
|
||
def upgrade() -> None: | ||
${upgrades if upgrades else "pass"} | ||
|
||
|
||
def downgrade() -> None: | ||
${downgrades if downgrades else "pass"} |
28 changes: 28 additions & 0 deletions
28
schemes/migrations/versions/bfc3cbc1bb13_create_users_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Create users table | ||
Revision ID: bfc3cbc1bb13 | ||
Revises: | ||
Create Date: 2023-10-20 10:15:51.912421 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
revision: str = "bfc3cbc1bb13" | ||
down_revision: Union[str, None] = None | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.create_table( | ||
"users", | ||
sa.Column("id", sa.Integer, primary_key=True), | ||
sa.Column("email", sa.String(256), nullable=False, unique=True), | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_table("users") |