main
py 50 lines 2.05 KB
Raw
1 """Add license cache table
2
3 Revision ID: 6796a7d001ad
4 Revises: 8e3b57c8bbb2
5 Create Date: 2025-09-02 09:58:22.242700
6
7 """
8 from typing import Sequence
9 from typing import Union
10
11 import sqlalchemy as sa
12
13 from alembic import op
14
15 # revision identifiers, used by Alembic.
16 revision: str = "6796a7d001ad"
17 down_revision: Union[str, None] = "8e3b57c8bbb2"
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 # ### commands auto generated by Alembic - please adjust! ###
24 op.create_table(
25 "license_cache",
26 sa.Column("id", sa.Integer(), nullable=False),
27 sa.Column("license_key", sa.String(length=1024), nullable=False),
28 sa.Column("feature_name", sa.String(length=256), nullable=False),
29 sa.Column("is_enabled", sa.Boolean(), nullable=False),
30 sa.Column("cached_at", sa.DateTime(), nullable=False),
31 sa.Column("expires_at", sa.DateTime(), nullable=False),
32 sa.Column("license_data", sa.String(length=5000), nullable=True),
33 sa.PrimaryKeyConstraint("id"),
34 )
35 op.create_index(op.f("ix_license_cache_cached_at"), "license_cache", ["cached_at"], unique=False)
36 op.create_index(op.f("ix_license_cache_expires_at"), "license_cache", ["expires_at"], unique=False)
37 op.create_index(op.f("ix_license_cache_feature_name"), "license_cache", ["feature_name"], unique=False)
38
39 # Create partial index on license_key (first 255 characters to avoid MySQL key length limit)
40 op.execute("CREATE INDEX ix_license_cache_license_key ON license_cache (license_key(255))")
41
42
43 def downgrade() -> None:
44 # ### commands auto generated by Alembic - please adjust! ###
45 op.drop_index("ix_license_cache_license_key", table_name="license_cache")
46 op.drop_index(op.f("ix_license_cache_feature_name"), table_name="license_cache")
47 op.drop_index(op.f("ix_license_cache_expires_at"), table_name="license_cache")
48 op.drop_index(op.f("ix_license_cache_cached_at"), table_name="license_cache")
49 op.drop_table("license_cache")
50 # ### end Alembic commands ###