
- Add PublicStream model and migration - Update list_streams.py and upload.py to use database - Add import script for data migration - Remove public_streams.txt (replaced by database) - Fix quota sync between userquota and publicstream tables
72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
"""Add PublicStream model
|
|
|
|
Revision ID: 0df481ee920b
|
|
Revises: f86c93c7a872
|
|
Create Date: 2025-07-19 10:02:22.902696
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = '0df481ee920b'
|
|
down_revision: Union[str, Sequence[str], None] = 'f86c93c7a872'
|
|
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! ###
|
|
# First create the new publicstream table
|
|
op.create_table('publicstream',
|
|
sa.Column('uid', sa.String(), nullable=False),
|
|
sa.Column('size', sa.Integer(), nullable=False),
|
|
sa.Column('mtime', sa.Integer(), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(), nullable=False),
|
|
sa.Column('updated_at', sa.DateTime(), nullable=False),
|
|
sa.PrimaryKeyConstraint('uid')
|
|
)
|
|
|
|
# Drop the foreign key constraint first
|
|
op.drop_constraint('dbsession_user_id_fkey', 'dbsession', type_='foreignkey')
|
|
|
|
# Then drop the unique constraint
|
|
op.drop_constraint(op.f('uq_user_username'), 'user', type_='unique')
|
|
|
|
# Create the new index
|
|
op.create_index(op.f('ix_user_username'), 'user', ['username'], unique=True)
|
|
|
|
# Recreate the foreign key constraint
|
|
op.create_foreign_key(
|
|
'dbsession_user_id_fkey', 'dbsession', 'user',
|
|
['user_id'], ['username'], ondelete='CASCADE'
|
|
)
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""Downgrade schema."""
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
# Drop the foreign key constraint first
|
|
op.drop_constraint('dbsession_user_id_fkey', 'dbsession', type_='foreignkey')
|
|
|
|
# Drop the index
|
|
op.drop_index(op.f('ix_user_username'), table_name='user')
|
|
|
|
# Recreate the unique constraint
|
|
op.create_unique_constraint(op.f('uq_user_username'), 'user', ['username'])
|
|
|
|
# Recreate the foreign key constraint
|
|
op.create_foreign_key(
|
|
'dbsession_user_id_fkey', 'dbsession', 'user',
|
|
['user_id'], ['username'], ondelete='CASCADE'
|
|
)
|
|
|
|
# Drop the publicstream table
|
|
op.drop_table('publicstream')
|
|
# ### end Alembic commands ###
|