Add subcription feature 3

This commit is contained in:
Urtzi Alfaro
2026-01-15 20:45:49 +01:00
parent a4c3b7da3f
commit b674708a4c
83 changed files with 9451 additions and 6828 deletions

View File

@@ -100,6 +100,13 @@ def upgrade() -> None:
sa.Column('owner_id', sa.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False, server_default=sa.text('CURRENT_TIMESTAMP'), onupdate=sa.text('CURRENT_TIMESTAMP')),
# 3D Secure (3DS) tracking
sa.Column('threeds_authentication_required', sa.Boolean(), nullable=True, server_default='FALSE'),
sa.Column('threeds_authentication_required_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('threeds_authentication_completed', sa.Boolean(), nullable=True, server_default='FALSE'),
sa.Column('threeds_authentication_completed_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('last_threeds_setup_intent_id', sa.String(length=255), nullable=True),
sa.Column('threeds_action_type', sa.String(length=100), nullable=True),
# Enterprise tier hierarchy fields
sa.Column('parent_tenant_id', sa.UUID(), nullable=True),
sa.Column('tenant_type', sa.String(length=50), nullable=False, server_default='standalone'),
@@ -237,6 +244,13 @@ def upgrade() -> None:
sa.Column('is_tenant_linked', sa.Boolean(), nullable=False, server_default='FALSE'),
sa.Column('tenant_linking_status', sa.String(length=50), nullable=True),
sa.Column('linked_at', sa.DateTime(), nullable=True),
# 3D Secure (3DS) tracking
sa.Column('threeds_authentication_required', sa.Boolean(), nullable=True, server_default='FALSE'),
sa.Column('threeds_authentication_required_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('threeds_authentication_completed', sa.Boolean(), nullable=True, server_default='FALSE'),
sa.Column('threeds_authentication_completed_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('last_threeds_setup_intent_id', sa.String(length=255), nullable=True),
sa.Column('threeds_action_type', sa.String(length=100), nullable=True),
# Features and metadata
sa.Column('features', sa.JSON(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False, server_default=sa.text('CURRENT_TIMESTAMP')),

View File

@@ -0,0 +1,51 @@
"""Fix tenant_id nullable constraint for tenant-independent subscriptions
This migration fixes the database schema issue where tenant_id was incorrectly
defined as NOT NULL, preventing tenant-independent subscription creation during
registration.
Revision ID: 002_fix_tenant_id_nullable
Revises: 001_unified_initial_schema
Create Date: 2026-01-15 19:00:00.000000+00:00
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '002_fix_tenant_id_nullable'
down_revision: Union[str, None] = '001_unified_initial_schema'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# First, drop the foreign key constraint temporarily
op.drop_constraint('subscriptions_tenant_id_fkey', 'subscriptions', type_='foreignkey')
# Alter the tenant_id column to be nullable
op.alter_column('subscriptions', 'tenant_id',
existing_type=sa.UUID(),
nullable=True)
# Recreate the foreign key constraint
op.create_foreign_key('subscriptions_tenant_id_fkey', 'subscriptions', 'tenants',
['tenant_id'], ['id'], ondelete='CASCADE')
def downgrade() -> None:
# Drop the foreign key constraint temporarily
op.drop_constraint('subscriptions_tenant_id_fkey', 'subscriptions', type_='foreignkey')
# Revert the tenant_id column to be non-nullable
# Note: This will fail if there are any records with tenant_id = NULL
op.alter_column('subscriptions', 'tenant_id',
existing_type=sa.UUID(),
nullable=False)
# Recreate the foreign key constraint
op.create_foreign_key('subscriptions_tenant_id_fkey', 'subscriptions', 'tenants',
['tenant_id'], ['id'], ondelete='CASCADE')