Initial commit — PlantGuideScraper project
This commit is contained in:
53
backend/alembic/versions/002_add_cached_stats_and_indexes.py
Normal file
53
backend/alembic/versions/002_add_cached_stats_and_indexes.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""Add cached_stats table and license index
|
||||
|
||||
Revision ID: 002
|
||||
Revises: 001
|
||||
Create Date: 2025-01-25
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision: str = '002'
|
||||
down_revision: Union[str, None] = '001'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Cached stats table for pre-calculated dashboard statistics
|
||||
op.create_table(
|
||||
'cached_stats',
|
||||
sa.Column('id', sa.Integer(), primary_key=True),
|
||||
sa.Column('key', sa.String(50), nullable=False, unique=True),
|
||||
sa.Column('value', sa.Text(), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.now()),
|
||||
)
|
||||
op.create_index('ix_cached_stats_key', 'cached_stats', ['key'])
|
||||
|
||||
# Add license index to images table (if not exists)
|
||||
# Using batch mode for SQLite compatibility
|
||||
try:
|
||||
op.create_index('ix_images_license', 'images', ['license'])
|
||||
except Exception:
|
||||
pass # Index may already exist
|
||||
|
||||
# Add only_without_images column to jobs if it doesn't exist
|
||||
try:
|
||||
op.add_column('jobs', sa.Column('only_without_images', sa.Boolean(), default=False))
|
||||
except Exception:
|
||||
pass # Column may already exist
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
try:
|
||||
op.drop_index('ix_images_license', 'images')
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
op.drop_column('jobs', 'only_without_images')
|
||||
except Exception:
|
||||
pass
|
||||
op.drop_table('cached_stats')
|
||||
Reference in New Issue
Block a user