diff options
| -rw-r--r-- | alembic/versions/5d998cafe1ba_init_database.py | 55 | ||||
| -rw-r--r-- | alembic/versions/940afc736a0f_init_database.py | 72 | ||||
| -rw-r--r-- | models/__init__.py | 2 | ||||
| -rw-r--r-- | models/announcement.py | 5 | ||||
| -rw-r--r-- | models/suggest.py | 7 | ||||
| -rw-r--r-- | models/user.py | 2 |
6 files changed, 85 insertions, 58 deletions
diff --git a/alembic/versions/5d998cafe1ba_init_database.py b/alembic/versions/5d998cafe1ba_init_database.py deleted file mode 100644 index e55e4ed..0000000 --- a/alembic/versions/5d998cafe1ba_init_database.py +++ /dev/null | |||
| @@ -1,55 +0,0 @@ | |||
| 1 | """init database | ||
| 2 | |||
| 3 | Revision ID: 5d998cafe1ba | ||
| 4 | Revises: | ||
| 5 | Create Date: 2026-03-23 00:05:14.621886 | ||
| 6 | |||
| 7 | """ | ||
| 8 | from typing import Sequence, Union | ||
| 9 | |||
| 10 | from alembic import op | ||
| 11 | import sqlalchemy as sa | ||
| 12 | |||
| 13 | |||
| 14 | # revision identifiers, used by Alembic. | ||
| 15 | revision: str = '5d998cafe1ba' | ||
| 16 | down_revision: Union[str, Sequence[str], None] = None | ||
| 17 | branch_labels: Union[str, Sequence[str], None] = None | ||
| 18 | depends_on: Union[str, Sequence[str], None] = None | ||
| 19 | |||
| 20 | |||
| 21 | def upgrade() -> None: | ||
| 22 | """Upgrade schema.""" | ||
| 23 | # ### commands auto generated by Alembic - please adjust! ### | ||
| 24 | op.create_table('invoice', | ||
| 25 | sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), | ||
| 26 | sa.Column('amount', sa.Float(), nullable=False), | ||
| 27 | sa.Column('datetime', sa.DateTime(), nullable=False), | ||
| 28 | sa.PrimaryKeyConstraint('id', name=op.f('pk_invoice')) | ||
| 29 | ) | ||
| 30 | op.create_table('user', | ||
| 31 | sa.Column('id', sa.Integer(), autoincrement=False, nullable=False), | ||
| 32 | sa.Column('role', sa.Enum('REGULAR', 'ADMIN', name='userrole'), nullable=False), | ||
| 33 | sa.Column('vpn_link', sa.String(), nullable=False), | ||
| 34 | sa.PrimaryKeyConstraint('id', name=op.f('pk_user')) | ||
| 35 | ) | ||
| 36 | op.create_table('payment', | ||
| 37 | sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), | ||
| 38 | sa.Column('user_id', sa.Integer(), nullable=False), | ||
| 39 | sa.Column('invoice_id', sa.Integer(), nullable=False), | ||
| 40 | sa.Column('receipt_file_id', sa.String(), nullable=False), | ||
| 41 | sa.Column('datetime', sa.DateTime(), nullable=False), | ||
| 42 | sa.ForeignKeyConstraint(['invoice_id'], ['invoice.id'], name=op.f('fk_payment_invoice_id_invoice')), | ||
| 43 | sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('fk_payment_user_id_user')), | ||
| 44 | sa.PrimaryKeyConstraint('id', name=op.f('pk_payment')) | ||
| 45 | ) | ||
| 46 | # ### end Alembic commands ### | ||
| 47 | |||
| 48 | |||
| 49 | def downgrade() -> None: | ||
| 50 | """Downgrade schema.""" | ||
| 51 | # ### commands auto generated by Alembic - please adjust! ### | ||
| 52 | op.drop_table('payment') | ||
| 53 | op.drop_table('user') | ||
| 54 | op.drop_table('invoice') | ||
| 55 | # ### end Alembic commands ### | ||
diff --git a/alembic/versions/940afc736a0f_init_database.py b/alembic/versions/940afc736a0f_init_database.py new file mode 100644 index 0000000..bfaa771 --- /dev/null +++ b/alembic/versions/940afc736a0f_init_database.py | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | """init database | ||
| 2 | |||
| 3 | Revision ID: 940afc736a0f | ||
| 4 | Revises: | ||
| 5 | Create Date: 2026-03-23 02:21:35.245634 | ||
| 6 | |||
| 7 | """ | ||
| 8 | |||
| 9 | from typing import Sequence, Union | ||
| 10 | |||
| 11 | import sqlalchemy as sa | ||
| 12 | |||
| 13 | from alembic import op | ||
| 14 | |||
| 15 | # revision identifiers, used by Alembic. | ||
| 16 | revision: str = "940afc736a0f" | ||
| 17 | down_revision: Union[str, Sequence[str], None] = None | ||
| 18 | branch_labels: Union[str, Sequence[str], None] = None | ||
| 19 | depends_on: Union[str, Sequence[str], None] = None | ||
| 20 | |||
| 21 | |||
| 22 | def upgrade() -> None: | ||
| 23 | """Upgrade schema.""" | ||
| 24 | # ### commands auto generated by Alembic - please adjust! ### | ||
| 25 | op.create_table( | ||
| 26 | "announcement", | ||
| 27 | sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), | ||
| 28 | sa.Column("message", sa.JSON(), nullable=False), | ||
| 29 | sa.Column("datetime", sa.DateTime(), nullable=False), | ||
| 30 | sa.PrimaryKeyConstraint("id", name=op.f("pk_announcement")), | ||
| 31 | ) | ||
| 32 | op.create_table( | ||
| 33 | "invoice", | ||
| 34 | sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), | ||
| 35 | sa.Column("amount", sa.Float(), nullable=False), | ||
| 36 | sa.Column("datetime", sa.DateTime(), nullable=False), | ||
| 37 | sa.PrimaryKeyConstraint("id", name=op.f("pk_invoice")), | ||
| 38 | ) | ||
| 39 | op.create_table( | ||
| 40 | "user", | ||
| 41 | sa.Column("id", sa.Integer(), autoincrement=False, nullable=False), | ||
| 42 | sa.Column("role", sa.Enum("REGULAR", "ADMIN", name="userrole"), nullable=False), | ||
| 43 | sa.Column("vpn_link", sa.String(), nullable=False), | ||
| 44 | sa.Column("datetime", sa.DateTime(), nullable=False), | ||
| 45 | sa.PrimaryKeyConstraint("id", name=op.f("pk_user")), | ||
| 46 | ) | ||
| 47 | op.create_table( | ||
| 48 | "payment", | ||
| 49 | sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), | ||
| 50 | sa.Column("user_id", sa.Integer(), nullable=False), | ||
| 51 | sa.Column("invoice_id", sa.Integer(), nullable=False), | ||
| 52 | sa.Column("receipt_file_id", sa.String(), nullable=False), | ||
| 53 | sa.Column("datetime", sa.DateTime(), nullable=False), | ||
| 54 | sa.ForeignKeyConstraint( | ||
| 55 | ["invoice_id"], ["invoice.id"], name=op.f("fk_payment_invoice_id_invoice") | ||
| 56 | ), | ||
| 57 | sa.ForeignKeyConstraint( | ||
| 58 | ["user_id"], ["user.id"], name=op.f("fk_payment_user_id_user") | ||
| 59 | ), | ||
| 60 | sa.PrimaryKeyConstraint("id", name=op.f("pk_payment")), | ||
| 61 | ) | ||
| 62 | # ### end Alembic commands ### | ||
| 63 | |||
| 64 | |||
| 65 | def downgrade() -> None: | ||
| 66 | """Downgrade schema.""" | ||
| 67 | # ### commands auto generated by Alembic - please adjust! ### | ||
| 68 | op.drop_table("payment") | ||
| 69 | op.drop_table("user") | ||
| 70 | op.drop_table("invoice") | ||
| 71 | op.drop_table("announcement") | ||
| 72 | # ### end Alembic commands ### | ||
diff --git a/models/__init__.py b/models/__init__.py index 412f467..9d56b33 100644 --- a/models/__init__.py +++ b/models/__init__.py | |||
| @@ -4,6 +4,7 @@ from .rich_text import RichText | |||
| 4 | from .user import User | 4 | from .user import User |
| 5 | from .invoce import Invoice | 5 | from .invoce import Invoice |
| 6 | from .payment import Payment | 6 | from .payment import Payment |
| 7 | from .announcement import Announcement | ||
| 7 | # isort: on | 8 | # isort: on |
| 8 | 9 | ||
| 9 | __all__ = [ | 10 | __all__ = [ |
| @@ -12,4 +13,5 @@ __all__ = [ | |||
| 12 | "Invoice", | 13 | "Invoice", |
| 13 | "Payment", | 14 | "Payment", |
| 14 | "RichText", | 15 | "RichText", |
| 16 | "Announcement", | ||
| 15 | ] | 17 | ] |
diff --git a/models/announcement.py b/models/announcement.py index 9a6eef2..7243684 100644 --- a/models/announcement.py +++ b/models/announcement.py | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | from datetime import datetime | ||
| 2 | |||
| 1 | from sqlalchemy import JSON | 3 | from sqlalchemy import JSON |
| 2 | from sqlalchemy.orm import Mapped, mapped_column | 4 | from sqlalchemy.orm import Mapped, mapped_column |
| 3 | 5 | ||
| @@ -9,11 +11,12 @@ class Announcement(BaseTable): | |||
| 9 | 11 | ||
| 10 | id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) | 12 | id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) |
| 11 | __message: Mapped[str] = mapped_column("message", JSON()) | 13 | __message: Mapped[str] = mapped_column("message", JSON()) |
| 14 | datetime: Mapped[datetime] | ||
| 12 | 15 | ||
| 13 | @property | 16 | @property |
| 14 | def message(self) -> RichText: | 17 | def message(self) -> RichText: |
| 15 | return RichText.model_validate_json(self.__message) | 18 | return RichText.model_validate_json(self.__message) |
| 16 | 19 | ||
| 17 | @message.setter | 20 | @message.setter |
| 18 | def message_set(self, value: RichText) -> None: | 21 | def message(self, value: RichText) -> None: |
| 19 | self.__message = value.model_dump_json() | 22 | self.__message = value.model_dump_json() |
diff --git a/models/suggest.py b/models/suggest.py index 1ba18a0..a76a004 100644 --- a/models/suggest.py +++ b/models/suggest.py | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | from datetime import datetime | ||
| 2 | |||
| 1 | from sqlalchemy import JSON | 3 | from sqlalchemy import JSON |
| 2 | from sqlalchemy.orm import Mapped, mapped_column | 4 | from sqlalchemy.orm import Mapped, mapped_column |
| 3 | from sqlalchemy.sql.schema import ForeignKey | 5 | from sqlalchemy.sql.schema import ForeignKey |
| @@ -13,11 +15,12 @@ class Suggest(BaseTable): | |||
| 13 | user_id: Mapped[int] = mapped_column(ForeignKey(User.id)) | 15 | user_id: Mapped[int] = mapped_column(ForeignKey(User.id)) |
| 14 | suggested_user_id: Mapped[int] | 16 | suggested_user_id: Mapped[int] |
| 15 | __message: Mapped[str] = mapped_column("message", JSON()) | 17 | __message: Mapped[str] = mapped_column("message", JSON()) |
| 18 | datetime: Mapped[datetime] | ||
| 16 | 19 | ||
| 17 | @property | 20 | @property |
| 18 | def message(self) -> RichText: | 21 | def message(self) -> RichText: |
| 19 | return RichText.model_validate_json(self.__message) | 22 | return RichText.model_validate_json(self.__message) |
| 20 | 23 | ||
| 21 | @message.setter | 24 | @message.setter |
| 22 | def message_set(self, value: RichText) -> None: | 25 | def message(self, value: RichText) -> None: |
| 23 | self.__message = value.model_dump_json() | 26 | self.__message = value.model_dump_json(ensure_ascii=False) |
diff --git a/models/user.py b/models/user.py index 4983a13..690083c 100644 --- a/models/user.py +++ b/models/user.py | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | from datetime import datetime | ||
| 1 | from enum import IntEnum | 2 | from enum import IntEnum |
| 2 | 3 | ||
| 3 | from sqlalchemy.orm import Mapped, mapped_column | 4 | from sqlalchemy.orm import Mapped, mapped_column |
| @@ -16,6 +17,7 @@ class User(BaseTable): | |||
| 16 | id: Mapped[int] = mapped_column(primary_key=True, autoincrement=False) | 17 | id: Mapped[int] = mapped_column(primary_key=True, autoincrement=False) |
| 17 | role: Mapped[UserRole] = mapped_column(default=UserRole.REGULAR) | 18 | role: Mapped[UserRole] = mapped_column(default=UserRole.REGULAR) |
| 18 | vpn_link: Mapped[str] | 19 | vpn_link: Mapped[str] |
| 20 | datetime: Mapped[datetime] | ||
| 19 | 21 | ||
| 20 | def is_regular(self) -> bool: | 22 | def is_regular(self) -> bool: |
| 21 | return self.role >= UserRole.REGULAR | 23 | return self.role >= UserRole.REGULAR |
