Files
Juan DenisandClaude Opus 4.8 478b24a3cb feat: Phase 3 team & scale — projects/environments, shared resources, PR previews, proxy stacks
- Project / Environment hierarchy (C2): Workspace -> Project -> Environment
  org model. New Project/Environment models + CRUD APIs, nullable
  applications.project_id/environment_id (opt-in, no destructive backfill),
  ProjectService.ensure_default, a Projects list + ProjectDetail (env tabs),
  a project/environment selector in the create wizard, and sidebar nav.

- Polymorphic shared resources facade (C9): ResourceTag + SharedVariableGroup
  /SharedVariable/attachment models keyed by (resource_type, resource_id),
  reusing the env-var Fernet encryption; SharedResourceService resolves merged
  variables (most-recent attachment wins) with secrets masked. /api/v1/shared
  endpoints + reusable TagsPanel/EnvironmentVariablesPanel + a Shared Variables
  management page. Existing per-resource tables untouched (facade first).

- PR preview environments (C3): ApplicationPreview + settings models, a
  PreviewService with pure domain-templating + reconcile (open PRs vs active
  previews) cores and best-effort provisioning (incl. guarded WordPress
  file+DB clone), a pull_request webhook endpoint, preview.* jobs, and a
  Previews tab on the app detail page.

- Per-server managed proxy stack (C6): opt-in Dockerized Traefik/Caddy as a
  Compose stack (host Nginx stays default and superior for PHP/WordPress).
  ProxyStack model + ProxyStackService with pure compose/config generators and
  versioned config backups, /api/v1/servers/<id>/proxy endpoints, and a Proxy
  tab on the server detail page.

Migrations 031-034 add the new tables/columns; the full chain applies cleanly
from an empty DB. Full backend suite: 871 passed, 14 skipped; frontend builds.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 19:33:44 -04:00

97 lines
4.0 KiB
Python

"""Polymorphic shared resources (facade layer).
Adds:
- resource_tags
- shared_variable_groups, shared_variables, shared_variable_group_attachments
Tags and shared variable groups attach to any resource via (resource_type,
resource_id). Existing per-resource env var tables are untouched (facade first).
Idempotent: MigrationService runs _fix_missing_columns() + db.create_all() on boot
before Alembic, so guard on the live schema.
Revision ID: 032_shared_resources
Revises: 031_projects_environments
Create Date: 2026-06-23
"""
from alembic import op
import sqlalchemy as sa
revision = '032_shared_resources'
down_revision = '031_projects_environments'
branch_labels = None
depends_on = None
def upgrade():
conn = op.get_bind()
inspector = sa.inspect(conn)
existing = set(inspector.get_table_names())
if 'resource_tags' not in existing:
op.create_table(
'resource_tags',
sa.Column('id', sa.Integer, nullable=False),
sa.Column('resource_type', sa.String(50), nullable=False),
sa.Column('resource_id', sa.String(255), nullable=False),
sa.Column('tag', sa.String(100), nullable=False),
sa.Column('created_at', sa.DateTime, nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('resource_type', 'resource_id', 'tag', name='uq_resource_tag'),
)
op.create_index('ix_resource_tags_resource', 'resource_tags', ['resource_type', 'resource_id'])
if 'shared_variable_groups' not in existing:
op.create_table(
'shared_variable_groups',
sa.Column('id', sa.Integer, nullable=False),
sa.Column('scope_type', sa.String(50), nullable=False),
sa.Column('scope_id', sa.String(255), nullable=False),
sa.Column('name', sa.String(255), nullable=False),
sa.Column('description', sa.String(500), nullable=True),
sa.Column('created_at', sa.DateTime, nullable=True),
sa.Column('updated_at', sa.DateTime, nullable=True),
sa.PrimaryKeyConstraint('id'),
)
op.create_index('ix_shared_variable_groups_scope', 'shared_variable_groups', ['scope_type', 'scope_id'])
if 'shared_variables' not in existing:
op.create_table(
'shared_variables',
sa.Column('id', sa.Integer, nullable=False),
sa.Column('group_id', sa.Integer, nullable=False),
sa.Column('key', sa.String(255), nullable=False),
sa.Column('encrypted_value', sa.Text, nullable=False),
sa.Column('is_secret', sa.Boolean, nullable=True),
sa.Column('created_at', sa.DateTime, nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.ForeignKeyConstraint(['group_id'], ['shared_variable_groups.id']),
sa.UniqueConstraint('group_id', 'key', name='uq_shared_variable_group_key'),
)
if 'shared_variable_group_attachments' not in existing:
op.create_table(
'shared_variable_group_attachments',
sa.Column('id', sa.Integer, nullable=False),
sa.Column('group_id', sa.Integer, nullable=False),
sa.Column('resource_type', sa.String(50), nullable=False),
sa.Column('resource_id', sa.String(255), nullable=False),
sa.Column('created_at', sa.DateTime, nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.ForeignKeyConstraint(['group_id'], ['shared_variable_groups.id']),
sa.UniqueConstraint('group_id', 'resource_type', 'resource_id', name='uq_shared_variable_attachment'),
)
op.create_index(
'ix_shared_variable_group_attachments_resource',
'shared_variable_group_attachments', ['resource_type', 'resource_id'],
)
def downgrade():
conn = op.get_bind()
inspector = sa.inspect(conn)
existing = set(inspector.get_table_names())
for tbl in ('shared_variable_group_attachments', 'shared_variables', 'shared_variable_groups', 'resource_tags'):
if tbl in existing:
op.drop_table(tbl)