Skip to content

Commit

Permalink
improve(db/model): add server type
Browse files Browse the repository at this point in the history
  • Loading branch information
erfjab committed Dec 8, 2024
1 parent 166d96a commit e61ccf2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -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 ###

This file was deleted.

5 changes: 3 additions & 2 deletions holderbot/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
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"

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)

Expand Down
5 changes: 5 additions & 0 deletions holderbot/models/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from enum import Enum

class ServerType(str, Enum):
MARZBAN = "marzban"
MARZNESHIN = "marzneshin"

0 comments on commit e61ccf2

Please sign in to comment.