diff --git a/holderbot/db/migrations/versions/20241208_2762ffee09bc_init_migration.py b/holderbot/db/migrations/versions/20241208_2762ffee09bc_init_migration.py new file mode 100644 index 0000000..db6eda7 --- /dev/null +++ b/holderbot/db/migrations/versions/20241208_2762ffee09bc_init_migration.py @@ -0,0 +1,48 @@ +"""init migration + +Revision ID: 2762ffee09bc +Revises: +Create Date: 2024-12-08 19:41:44.519493 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = '2762ffee09bc' +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: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('servers', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('remark', sa.String(length=32), nullable=False), + sa.Column('active', sa.Boolean(), nullable=False), + sa.Column('type', sa.String(), nullable=False), + sa.Column('data', sa.JSON(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('access', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('server_id', sa.Integer(), nullable=False), + sa.Column('token', sa.String(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.ForeignKeyConstraint(['server_id'], ['servers.id'], ondelete='CASCADE'), + sa.PrimaryKeyConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('access') + op.drop_table('servers') + # ### end Alembic commands ### \ No newline at end of file diff --git a/holderbot/db/migrations/versions/20241208_29c9ed225e2f_init_migration.py b/holderbot/db/migrations/versions/20241208_29c9ed225e2f_init_migration.py deleted file mode 100644 index 9b790f6..0000000 --- a/holderbot/db/migrations/versions/20241208_29c9ed225e2f_init_migration.py +++ /dev/null @@ -1,50 +0,0 @@ -"""init migration - -Revision ID: 29c9ed225e2f -Revises: -Create Date: 2024-12-08 19:02:06.242374 - -""" - -from typing import Sequence, Union - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision: str = "29c9ed225e2f" -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: - # ### commands auto generated by Alembic - please adjust! ### - op.create_table( - "servers", - sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), - sa.Column("remark", sa.String(length=32), nullable=False), - sa.Column("active", sa.Boolean(), nullable=False), - sa.Column("data", sa.JSON(), nullable=False), - sa.Column("created_at", sa.DateTime(), nullable=False), - sa.PrimaryKeyConstraint("id"), - ) - op.create_table( - "access", - sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), - sa.Column("server_id", sa.Integer(), nullable=False), - sa.Column("token", sa.String(), nullable=False), - sa.Column("updated_at", sa.DateTime(), nullable=False), - sa.Column("created_at", sa.DateTime(), nullable=False), - sa.ForeignKeyConstraint(["server_id"], ["servers.id"], ondelete="CASCADE"), - sa.PrimaryKeyConstraint("id"), - ) - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - op.drop_table("access") - op.drop_table("servers") - # ### end Alembic commands ### diff --git a/holderbot/db/models.py b/holderbot/db/models.py index 1438c50..5fe6bb5 100644 --- a/holderbot/db/models.py +++ b/holderbot/db/models.py @@ -2,8 +2,8 @@ from sqlalchemy import Integer, DateTime, String, Boolean, JSON, ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship from sqlalchemy.ext.hybrid import hybrid_property -from holderbot.db.base import Base - +from .base import Base +from holderbot.models.server import ServerType class Server(Base): __tablename__ = "servers" @@ -11,6 +11,7 @@ class Server(Base): id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) remark: Mapped[str] = mapped_column(String(32)) active: Mapped[bool] = mapped_column(Boolean, default=True) + type: Mapped[ServerType] = mapped_column(String, nullable=False) data: Mapped[dict] = mapped_column(JSON) created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow) diff --git a/holderbot/models/server.py b/holderbot/models/server.py new file mode 100644 index 0000000..884bc93 --- /dev/null +++ b/holderbot/models/server.py @@ -0,0 +1,5 @@ +from enum import Enum + +class ServerType(str, Enum): + MARZBAN = "marzban" + MARZNESHIN = "marzneshin"