feat(sub): subscription logic (pre release)
This commit is contained in:
46
alembic/versions/0ea5625b4913_order_durationdays.py
Normal file
46
alembic/versions/0ea5625b4913_order_durationdays.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""+order.durationdays
|
||||
|
||||
Revision ID: 0ea5625b4913
|
||||
Revises: b97ce5b7d663
|
||||
Create Date: 2026-08-02 13:17:18.429961
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '0ea5625b4913'
|
||||
down_revision: Union[str, Sequence[str], None] = 'b97ce5b7d663'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
orderstatus = postgresql.ENUM('PENDING', 'PAID', 'DISCARDED', name='orderstatus')
|
||||
orderstatus.create(op.get_bind())
|
||||
|
||||
op.create_unique_constraint(None, 'order_addons', ['id'])
|
||||
op.add_column('orders', sa.Column('duration_days', sa.INTEGER(), nullable=False))
|
||||
op.add_column('orders', sa.Column('status', sa.Enum('PENDING', 'PAID', 'DISCARDED', name='orderstatus'), nullable=False))
|
||||
op.create_unique_constraint(None, 'orders', ['id'])
|
||||
op.create_unique_constraint(None, 'subscription_addons', ['id'])
|
||||
op.create_unique_constraint(None, 'subscriptions', ['id'])
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(None, 'subscriptions', type_='unique')
|
||||
op.drop_constraint(None, 'subscription_addons', type_='unique')
|
||||
op.drop_constraint(None, 'orders', type_='unique')
|
||||
op.drop_column('orders', 'status')
|
||||
op.drop_column('orders', 'duration_days')
|
||||
op.drop_constraint(None, 'order_addons', type_='unique')
|
||||
# ### end Alembic commands ###
|
||||
72
alembic/versions/b97ce5b7d663_subscriptions_infra.py
Normal file
72
alembic/versions/b97ce5b7d663_subscriptions_infra.py
Normal file
@@ -0,0 +1,72 @@
|
||||
"""subscriptions infra
|
||||
|
||||
Revision ID: b97ce5b7d663
|
||||
Revises: 3d767875ec7d
|
||||
Create Date: 2026-08-02 12:38:25.357158
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'b97ce5b7d663'
|
||||
down_revision: Union[str, Sequence[str], None] = '3d767875ec7d'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('orders',
|
||||
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
|
||||
sa.Column('user_id', sa.INTEGER(), nullable=False),
|
||||
sa.Column('devices', sa.INTEGER(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('id'),
|
||||
sa.UniqueConstraint('user_id')
|
||||
)
|
||||
op.create_table('subscriptions',
|
||||
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
|
||||
sa.Column('user_id', sa.INTEGER(), nullable=False),
|
||||
sa.Column('devices', sa.INTEGER(), nullable=False),
|
||||
sa.Column('status', sa.Enum('ACTIVE', 'EXPIRED', name='subscriptionstatus'), nullable=False),
|
||||
sa.Column('expires_at', sa.DateTime(timezone=True), nullable=False),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('id'),
|
||||
sa.UniqueConstraint('user_id')
|
||||
)
|
||||
op.create_table('order_addons',
|
||||
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
|
||||
sa.Column('order_id', sa.INTEGER(), nullable=False),
|
||||
sa.Column('addon_id', sa.TEXT(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['addon_id'], ['addons.id'], ),
|
||||
sa.ForeignKeyConstraint(['order_id'], ['orders.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('id')
|
||||
)
|
||||
op.create_table('subscription_addons',
|
||||
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
|
||||
sa.Column('subscription_id', sa.INTEGER(), nullable=False),
|
||||
sa.Column('addon_id', sa.TEXT(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['addon_id'], ['addons.id'], ),
|
||||
sa.ForeignKeyConstraint(['subscription_id'], ['subscriptions.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('subscription_addons')
|
||||
op.drop_table('order_addons')
|
||||
op.drop_table('subscriptions')
|
||||
op.drop_table('orders')
|
||||
# ### end Alembic commands ###
|
||||
32
alembic/versions/bc424721d767_order_user_id_not_unique.py
Normal file
32
alembic/versions/bc424721d767_order_user_id_not_unique.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""order.user_id -> NOT UNIQUE
|
||||
|
||||
Revision ID: bc424721d767
|
||||
Revises: 0ea5625b4913
|
||||
Create Date: 2026-08-02 13:23:23.626697
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'bc424721d767'
|
||||
down_revision: Union[str, Sequence[str], None] = '0ea5625b4913'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(op.f('orders_user_id_key'), 'orders', type_='unique')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_unique_constraint(op.f('orders_user_id_key'), 'orders', ['user_id'], postgresql_nulls_not_distinct=False)
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user