feat: subs and views
This commit is contained in:
51
migration/versions/e7ab0b38a8bf_add_subscriptions_table.py
Normal file
51
migration/versions/e7ab0b38a8bf_add_subscriptions_table.py
Normal file
@@ -0,0 +1,51 @@
|
||||
"""add subscriptions table
|
||||
|
||||
Revision ID: e7ab0b38a8bf
|
||||
Revises: 6517eda4a92e
|
||||
Create Date: 2025-11-10 16:48:25.310928
|
||||
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'e7ab0b38a8bf'
|
||||
down_revision: str | None = '6517eda4a92e'
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table(
|
||||
'subscriptions',
|
||||
sa.Column('purchase_id', sa.Uuid(), nullable=False),
|
||||
sa.Column('user_telegram_id', sa.BigInteger(), nullable=False),
|
||||
sa.Column('username', sa.String(), nullable=True),
|
||||
sa.Column('invite_link', sa.String(), nullable=False),
|
||||
sa.Column('id', sa.Uuid(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
['purchase_id'],
|
||||
['purchases.id'],
|
||||
),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
)
|
||||
op.create_index(op.f('ix_subscriptions_invite_link'), 'subscriptions', ['invite_link'], unique=False)
|
||||
op.create_index(op.f('ix_subscriptions_purchase_id'), 'subscriptions', ['purchase_id'], unique=False)
|
||||
op.create_index(op.f('ix_subscriptions_user_telegram_id'), 'subscriptions', ['user_telegram_id'], unique=False)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index(op.f('ix_subscriptions_user_telegram_id'), table_name='subscriptions')
|
||||
op.drop_index(op.f('ix_subscriptions_purchase_id'), table_name='subscriptions')
|
||||
op.drop_index(op.f('ix_subscriptions_invite_link'), table_name='subscriptions')
|
||||
op.drop_table('subscriptions')
|
||||
# ### end Alembic commands ###
|
||||
67
migration/versions/fafe143ee0f4_add_views_tracking.py
Normal file
67
migration/versions/fafe143ee0f4_add_views_tracking.py
Normal file
@@ -0,0 +1,67 @@
|
||||
"""add views tracking
|
||||
|
||||
Revision ID: fafe143ee0f4
|
||||
Revises: e7ab0b38a8bf
|
||||
Create Date: 2025-11-10 16:57:28.652101
|
||||
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'fafe143ee0f4'
|
||||
down_revision: str | None = 'e7ab0b38a8bf'
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
|
||||
# Создаём enum тип для статуса доступности просмотров ПЕРЕД использованием
|
||||
op.execute("CREATE TYPE postviewsavailability AS ENUM ('UNKNOWN', 'AVAILABLE', 'UNAVAILABLE', 'MANUAL')")
|
||||
|
||||
op.create_table(
|
||||
'viewssnapshots',
|
||||
sa.Column('purchase_id', sa.Uuid(), nullable=False),
|
||||
sa.Column('views_count', sa.Integer(), nullable=False),
|
||||
sa.Column('fetched_at', sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column('id', sa.Uuid(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
['purchase_id'],
|
||||
['purchases.id'],
|
||||
),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
)
|
||||
op.create_index(op.f('ix_viewssnapshots_fetched_at'), 'viewssnapshots', ['fetched_at'], unique=False)
|
||||
op.create_index(op.f('ix_viewssnapshots_purchase_id'), 'viewssnapshots', ['purchase_id'], unique=False)
|
||||
op.add_column(
|
||||
'purchases',
|
||||
sa.Column(
|
||||
'views_availability',
|
||||
sa.Enum('UNKNOWN', 'AVAILABLE', 'UNAVAILABLE', 'MANUAL', name='postviewsavailability'),
|
||||
nullable=False,
|
||||
server_default='UNKNOWN',
|
||||
),
|
||||
)
|
||||
op.add_column('purchases', sa.Column('last_views_fetch_at', sa.DateTime(timezone=True), nullable=True))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('purchases', 'last_views_fetch_at')
|
||||
op.drop_column('purchases', 'views_availability')
|
||||
op.drop_index(op.f('ix_viewssnapshots_purchase_id'), table_name='viewssnapshots')
|
||||
op.drop_index(op.f('ix_viewssnapshots_fetched_at'), table_name='viewssnapshots')
|
||||
op.drop_table('viewssnapshots')
|
||||
|
||||
# Удаляём enum тип
|
||||
op.execute('DROP TYPE IF EXISTS postviewsavailability')
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user