-
Notifications
You must be signed in to change notification settings - Fork 22
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
8 changed files
with
119 additions
and
26 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
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
31 changes: 31 additions & 0 deletions
31
src/plugins/morning/plugins/hello/migrations/371e102dcdb9_add_bot_id.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,31 @@ | ||
"""add bot_id | ||
Revision ID: 371e102dcdb9 | ||
Revises: 5469ed61acff | ||
Create Date: 2023-09-30 08:39:55.899833 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "371e102dcdb9" | ||
down_revision = "5469ed61acff" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("hello_hello", schema=None) as batch_op: | ||
batch_op.add_column(sa.Column("bot_id", sa.String(), nullable=True)) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("hello_hello", schema=None) as batch_op: | ||
batch_op.drop_column("bot_id") | ||
|
||
# ### end Alembic commands ### |
2 changes: 1 addition & 1 deletion
2
...b35122585_remove_bot_id_platform_et_al.py → ...ons/9dbb35122585_remove_platform_et_al.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
"""remove bot_id platform et al | ||
"""remove platform et al | ||
Revision ID: 9dbb35122585 | ||
Revises: 92c2c4affdce | ||
|
38 changes: 38 additions & 0 deletions
38
src/plugins/morning/plugins/hello/migrations/b683352e0089_add_bot_id_data.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,38 @@ | ||
"""add bot_id data | ||
Revision ID: b683352e0089 | ||
Revises: 371e102dcdb9 | ||
Create Date: 2023-09-30 08:46:28.829111 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
from nonebot import get_driver | ||
from sqlalchemy.ext.automap import automap_base | ||
from sqlalchemy.orm import Session | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "b683352e0089" | ||
down_revision = "371e102dcdb9" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
Base = automap_base() | ||
Base.prepare(autoload_with=op.get_bind()) | ||
Hello = Base.classes.hello_hello | ||
config = get_driver().config | ||
migration_bot_id = getattr(config, "migration_bot_id", None) | ||
with Session(op.get_bind()) as session: | ||
hellos = session.scalars(sa.select(Hello)).all() | ||
if hellos and migration_bot_id is None: | ||
raise ValueError("你需要设置 migration_bot_id 以完成迁移") | ||
|
||
for hello in hellos: | ||
hello.bot_id = migration_bot_id | ||
session.commit() | ||
|
||
|
||
def downgrade() -> None: | ||
pass |
31 changes: 31 additions & 0 deletions
31
src/plugins/morning/plugins/hello/migrations/e92b0f680c78_make_bot_id_non_nullable.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,31 @@ | ||
"""make bot_id non-nullable | ||
Revision ID: e92b0f680c78 | ||
Revises: b683352e0089 | ||
Create Date: 2023-09-30 08:57:28.404492 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "e92b0f680c78" | ||
down_revision = "b683352e0089" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("hello_hello", schema=None) as batch_op: | ||
batch_op.alter_column("bot_id", existing_type=sa.VARCHAR(), nullable=False) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("hello_hello", schema=None) as batch_op: | ||
batch_op.alter_column("bot_id", existing_type=sa.VARCHAR(), nullable=True) | ||
|
||
# ### 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
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