-
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.
- Loading branch information
Showing
9 changed files
with
241 additions
and
71 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,56 @@ | ||
# type: ignore | ||
|
||
"""Add url to poll table | ||
Revision ID: a0556697d480 | ||
Revises: 82e8adf72f35 | ||
Create Date: 2024-09-03 21:58:21.606304 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.orm import Session | ||
|
||
try: | ||
import fastnanoid | ||
except ImportError: | ||
fastnanoid = None | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'a0556697d480' | ||
down_revision = '82e8adf72f35' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.add_column('poll', sa.Column('url', sa.VARCHAR(length=21), nullable=True)) | ||
|
||
connection = op.get_bind() | ||
session = Session(bind=connection) | ||
|
||
if fastnanoid is None: | ||
return | ||
|
||
try: | ||
rows = session.execute(sa.select([sa.table('poll')])).fetchall() | ||
|
||
for row in rows: | ||
session.execute( | ||
sa.update(sa.table('poll')) | ||
.where(sa.text('id = :id')) | ||
.values(url=fastnanoid.generate()), | ||
{'id': row['id']} | ||
) | ||
|
||
session.commit() | ||
finally: | ||
session.close() | ||
|
||
op.alter_column('poll', 'url', nullable=False) | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column('poll', 'url') | ||
# ### end Alembic commands ### |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
docker compose --progress quiet up database -d --quiet-pull | ||
docker compose --progress quiet build mybot | ||
docker compose --progress quiet run --rm -t -v "${PWD}/alembic:/app/alembic" mybot alembic "$@" |
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ dependencies = [ | |
"aiohttp", | ||
"python-dateutil", | ||
"typer", | ||
"fastnanoid", | ||
] | ||
requires-python = ">=3.12" | ||
|
||
|
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
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
Oops, something went wrong.