mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-10-29 08:07:37 +09:00
- 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>
87 lines
3.5 KiB
Python
87 lines
3.5 KiB
Python
"""Project / Environment hierarchy.
|
|
|
|
Adds:
|
|
- projects, environments
|
|
- applications.project_id / environment_id (nullable, opt-in)
|
|
|
|
Organizes apps under Workspace -> Project -> Environment. Columns stay nullable;
|
|
unassigned apps remain valid (no destructive backfill).
|
|
|
|
Idempotent: MigrationService runs _fix_missing_columns() + db.create_all() on boot
|
|
before Alembic, so guard on the live schema.
|
|
|
|
Revision ID: 031_projects_environments
|
|
Revises: 030_buildpacks_snapshots
|
|
Create Date: 2026-06-23
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
revision = '031_projects_environments'
|
|
down_revision = '030_buildpacks_snapshots'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
conn = op.get_bind()
|
|
inspector = sa.inspect(conn)
|
|
existing = set(inspector.get_table_names())
|
|
|
|
if 'projects' not in existing:
|
|
op.create_table(
|
|
'projects',
|
|
sa.Column('id', sa.Integer, nullable=False),
|
|
sa.Column('workspace_id', sa.Integer, nullable=False),
|
|
sa.Column('name', sa.String(128), nullable=False),
|
|
sa.Column('slug', sa.String(128), nullable=False),
|
|
sa.Column('description', sa.Text, nullable=True),
|
|
sa.Column('metadata_json', sa.Text, nullable=True),
|
|
sa.Column('created_at', sa.DateTime, nullable=True),
|
|
sa.Column('updated_at', sa.DateTime, nullable=True),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('workspace_id', 'slug', name='uq_project_workspace_slug'),
|
|
)
|
|
op.create_index('ix_projects_workspace_id', 'projects', ['workspace_id'])
|
|
|
|
if 'environments' not in existing:
|
|
op.create_table(
|
|
'environments',
|
|
sa.Column('id', sa.Integer, nullable=False),
|
|
sa.Column('project_id', sa.Integer, nullable=False),
|
|
sa.Column('name', sa.String(64), nullable=False),
|
|
sa.Column('slug', sa.String(64), nullable=False),
|
|
sa.Column('is_default', sa.Boolean, nullable=True),
|
|
sa.Column('order', sa.Integer, nullable=True),
|
|
sa.Column('created_at', sa.DateTime, nullable=True),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('project_id', 'slug', name='uq_environment_project_slug'),
|
|
)
|
|
op.create_index('ix_environments_project_id', 'environments', ['project_id'])
|
|
|
|
if 'applications' in existing:
|
|
cols = {c['name'] for c in inspector.get_columns('applications')}
|
|
# Plain columns (FK not enforceable via SQLite ALTER ADD COLUMN; the ORM
|
|
# still declares the relationship).
|
|
if 'project_id' not in cols:
|
|
op.add_column('applications', sa.Column('project_id', sa.Integer, nullable=True))
|
|
op.create_index('ix_applications_project_id', 'applications', ['project_id'])
|
|
if 'environment_id' not in cols:
|
|
op.add_column('applications', sa.Column('environment_id', sa.Integer, nullable=True))
|
|
op.create_index('ix_applications_environment_id', 'applications', ['environment_id'])
|
|
|
|
|
|
def downgrade():
|
|
conn = op.get_bind()
|
|
inspector = sa.inspect(conn)
|
|
existing = set(inspector.get_table_names())
|
|
if 'applications' in existing:
|
|
cols = {c['name'] for c in inspector.get_columns('applications')}
|
|
for col in ('environment_id', 'project_id'):
|
|
if col in cols:
|
|
op.drop_column('applications', col)
|
|
if 'environments' in existing:
|
|
op.drop_table('environments')
|
|
if 'projects' in existing:
|
|
op.drop_table('projects')
|