diff --git a/core/migrations/versions/0000_merged_all_migrations.py b/core/migrations/versions/0000_baseline.py similarity index 53% rename from core/migrations/versions/0000_merged_all_migrations.py rename to core/migrations/versions/0000_baseline.py index 212de77..13059d8 100644 --- a/core/migrations/versions/0000_merged_all_migrations.py +++ b/core/migrations/versions/0000_baseline.py @@ -1,51 +1,28 @@ -"""Merged all migrations - no chaining +"""Core baseline schema. -Revision ID: merged_all_001 -Revises: -Create Date: 2026-05-16 00:00:00.000000 +Squashes 0000_merged_all_migrations .. 0007_cloudflare_out into one file so a +fresh core install builds its schema in a single step, with none of the +tenancy/identity tables that were created and later moved to cloud. -This migration combines all previous migrations into a single file. -All down_revision chains have been removed. +The revision id deliberately reuses the old head, '0007_cloudflare_out'. +A database already migrated through the old chain is stamped with that id and +so is already "at" this baseline: nothing re-runs, no manual stamp is needed. +A fresh database runs this file once. The schema it produces was diffed +table-by-table against one built by the old chain. + +Add new migrations on top of this one; never edit it. """ from alembic import op import sqlalchemy as sa from sqlalchemy.dialects import mysql -from sqlalchemy import inspect -import json -# revision identifiers, used by Alembic. -revision = '0000_merged_all_migrations' +revision = '0007_cloudflare_out' down_revision = None branch_labels = None depends_on = None -# Default PCI filter config -DEFAULT_PCI_FILTERS = json.dumps({ - "filters": [ - {"vendor_id": "10de", "device_id": "*", "type": "gpu"}, # NVIDIA - {"vendor_id": "1002", "device_id": "*", "type": "gpu"}, # AMD - ] -}) - def upgrade(): - # === From 879385f419fb_first.py === - op.create_table('users', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('first_name', sa.String(length=255), nullable=False), - sa.Column('last_name', sa.String(length=255), nullable=False), - sa.Column('email', sa.String(length=255), nullable=False), - sa.Column('oidc_id', sa.String(length=255), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('description', mysql.LONGTEXT(), nullable=True), - sa.Column('status', sa.String(length=50), nullable=True), - sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('deleted', sa.Boolean(), nullable=False), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('email'), - sa.UniqueConstraint('oidc_id') - ) op.create_table('audit_entry', sa.Column('id', sa.String(length=36), nullable=False), sa.Column('object_id', sa.String(length=36), nullable=False), @@ -56,14 +33,16 @@ def upgrade(): sa.Column('user_id', sa.String(length=36), nullable=True), sa.Column('additional_data', mysql.LONGTEXT(), nullable=True), sa.Column('is_error', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), sa.PrimaryKeyConstraint('id') ) - op.create_table('certificate_revocation_lists', + op.create_table('gpu_models', + sa.Column('vendor_id', sa.String(length=10), nullable=True), + sa.Column('device_id', sa.String(length=10), nullable=True), + sa.Column('vendor_name', sa.String(length=100), nullable=True), + sa.Column('device_name', sa.String(length=200), nullable=True), + sa.Column('vram_mb', sa.Integer(), nullable=True), + sa.Column('architecture', sa.String(length=100), nullable=True), sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('crl_number', sa.Integer(), nullable=False), - sa.Column('crl_data', mysql.LONGTEXT(), nullable=True), - sa.Column('next_update', sa.DateTime(timezone=True), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('visible', sa.Boolean(), nullable=False), @@ -71,11 +50,15 @@ def upgrade(): sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('status', sa.String(length=50), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), sa.PrimaryKeyConstraint('id') ) + with op.batch_alter_table('gpu_models', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_gpu_models_tenant_id'), ['tenant_id'], unique=False) + op.create_table('images', sa.Column('location', sa.String(length=255), nullable=False), sa.Column('location_type', sa.String(length=50), nullable=True), @@ -92,11 +75,15 @@ def upgrade(): sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('status', sa.String(length=50), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), sa.PrimaryKeyConstraint('id') ) + with op.batch_alter_table('images', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_images_tenant_id'), ['tenant_id'], unique=False) + op.create_table('labels', sa.Column('target_object_type', sa.String(length=255), nullable=False), sa.Column('target_object_id', sa.String(length=36), nullable=False), @@ -112,11 +99,15 @@ def upgrade(): sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('status', sa.String(length=50), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), sa.PrimaryKeyConstraint('id') ) + with op.batch_alter_table('labels', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_labels_tenant_id'), ['tenant_id'], unique=False) + op.create_table('regions', sa.Column('private_region', sa.Boolean(), nullable=False), sa.Column('country', sa.String(length=255), nullable=False), @@ -125,6 +116,15 @@ def upgrade(): sa.Column('enrollment_key', sa.String(length=36), nullable=False), sa.Column('ip_address_range_northsouth', sa.String(length=255), nullable=True), sa.Column('ip_address_range_eastwest', sa.String(length=255), nullable=True), + sa.Column('default_ovs_bridge', sa.String(length=255), nullable=True), + sa.Column('pci_device_filters', sa.JSON(), nullable=True), + sa.Column('max_host_failures', sa.Integer(), nullable=False), + sa.Column('failure_time_window', sa.Integer(), nullable=False), + sa.Column('relocate_on_host_failure', sa.Boolean(), nullable=False), + sa.Column('host_failure_reallocation_delay', sa.Integer(), nullable=False), + sa.Column('failover_paused', sa.Boolean(), nullable=False), + sa.Column('pause_reason', sa.String(length=255), nullable=True), + sa.Column('pause_started_at', sa.DateTime(timezone=True), nullable=True), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), @@ -133,12 +133,73 @@ def upgrade(): sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('status', sa.String(length=50), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), sa.PrimaryKeyConstraint('id') ) - op.create_table('universes', + with op.batch_alter_table('regions', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_regions_tenant_id'), ['tenant_id'], unique=False) + + op.create_table('server_groups', + sa.Column('policy', sa.String(length=50), nullable=False, server_default=sa.text("'soft-affinity'")), + sa.Column('id', sa.String(length=36), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False, server_default=sa.text('current_timestamp()')), + sa.Column('updated_at', sa.DateTime(), nullable=False, server_default=sa.text('current_timestamp()')), + sa.Column('visible', sa.Boolean(), nullable=False, server_default=sa.text('1')), + sa.Column('name', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('description', mysql.LONGTEXT(), nullable=True), + sa.Column('status', sa.String(length=50), nullable=True), + sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), + sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), + sa.Column('deleted', sa.Boolean(), nullable=False, server_default=sa.text('0')), + sa.PrimaryKeyConstraint('id') + ) + with op.batch_alter_table('server_groups', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_server_groups_tenant_id'), ['tenant_id'], unique=False) + + op.create_table('tasks', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('worker_id', sa.String(length=64), nullable=True), + sa.Column('job_details', sa.Text(), nullable=True), + sa.Column('response', sa.Text(), nullable=True), + sa.Column('status', sa.Text(), nullable=True), + sa.Column('success', sa.Text(), nullable=True), + sa.Column('creation_time', sa.DateTime(), nullable=True), + sa.Column('start_time', sa.DateTime(), nullable=True), + sa.Column('finish_time', sa.DateTime(), nullable=True), + sa.Column('wait_time', sa.Float(), nullable=True), + sa.Column('execution_time', sa.Float(), nullable=True), + sa.Column('task_type', sa.String(length=50), nullable=False), + sa.Column('depends_on', sa.Integer(), nullable=True), + sa.Column('not_before', sa.DateTime(), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + with op.batch_alter_table('tasks', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_tasks_worker_id'), ['worker_id'], unique=False) + + op.create_table('workload_requests', + sa.Column('id', sa.String(length=36), nullable=False), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('payload', sa.JSON(), nullable=False), + sa.Column('status', sa.String(length=32), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('updated_at', sa.DateTime(), nullable=True), + sa.Column('workload_type', sa.String(length=32), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + with op.batch_alter_table('workload_requests', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_workload_requests_tenant_id'), ['tenant_id'], unique=False) + + op.create_table('host_gpus', + sa.Column('gpu_model_id', sa.String(length=36), nullable=False), + sa.Column('pci_address', sa.String(length=100), nullable=False), + sa.Column('workload_host_id', sa.String(length=36), nullable=True), + sa.Column('gpu_status', sa.String(length=50), nullable=False, server_default=sa.text("'available'")), + sa.Column('assigned_workload_id', sa.String(length=36), nullable=True), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), @@ -147,13 +208,31 @@ def upgrade(): sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('status', sa.String(length=50), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), + sa.ForeignKeyConstraint(['gpu_model_id'], ['gpu_models.id'], ), sa.PrimaryKeyConstraint('id') ) - op.create_table('projects', - sa.Column('universe_id', sa.String(length=36), nullable=False), + with op.batch_alter_table('host_gpus', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_host_gpus_tenant_id'), ['tenant_id'], unique=False) + + op.create_table('networks', + sa.Column('region_id', sa.String(length=36), nullable=False), + sa.Column('ipv4_cidr', sa.String(length=50), nullable=True), + sa.Column('ipv4_gateway', sa.String(length=50), nullable=True), + sa.Column('ipv4_dns_servers', sa.String(length=255), nullable=True), + sa.Column('dhcp_range_start', sa.String(length=50), nullable=True), + sa.Column('dhcp_range_end', sa.String(length=50), nullable=True), + sa.Column('nscontroller_ip', sa.String(length=50), nullable=True), + sa.Column('ipv6_cidr', sa.String(length=50), nullable=True), + sa.Column('ipv6_gateway', sa.String(length=50), nullable=True), + sa.Column('vni', sa.Integer(), nullable=False), + sa.Column('encapsulation', sa.String(length=50), nullable=False), + sa.Column('ovs_bridge', sa.String(length=255), nullable=True), + sa.Column('network_type', sa.String(length=255), nullable=True), + sa.Column('enable_host_nat', sa.Boolean(), server_default='0', nullable=False), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), @@ -162,12 +241,41 @@ def upgrade(): sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('status', sa.String(length=50), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), - sa.ForeignKeyConstraint(['universe_id'], ['universes.id'], ), + sa.ForeignKeyConstraint(['region_id'], ['regions.id'], ), sa.PrimaryKeyConstraint('id') ) + with op.batch_alter_table('networks', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_networks_tenant_id'), ['tenant_id'], unique=False) + + op.create_table('volumes', + sa.Column('path', sa.String(length=255), nullable=True), + sa.Column('type', sa.String(length=50), nullable=True), + sa.Column('source', sa.String(length=255), nullable=True), + sa.Column('size_gb', sa.Float(), nullable=False), + sa.Column('boot', sa.Boolean(), nullable=False), + sa.Column('image_id', sa.String(length=36), nullable=True), + sa.Column('id', sa.String(length=36), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('visible', sa.Boolean(), nullable=False), + sa.Column('name', sa.String(length=255), nullable=False), + sa.Column('description', mysql.LONGTEXT(), nullable=True), + sa.Column('status', sa.String(length=50), nullable=True), + sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), + sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), + sa.Column('deleted', sa.Boolean(), nullable=False), + sa.ForeignKeyConstraint(['image_id'], ['images.id'], ), + sa.PrimaryKeyConstraint('id') + ) + with op.batch_alter_table('volumes', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_volumes_tenant_id'), ['tenant_id'], unique=False) + op.create_table('workload_hosts', sa.Column('region_id', sa.String(length=36), nullable=False), sa.Column('secret_key', sa.String(length=36), nullable=False), @@ -194,53 +302,24 @@ def upgrade(): sa.Column('name', sa.String(length=255), nullable=False), sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), sa.ForeignKeyConstraint(['region_id'], ['regions.id'], ), sa.PrimaryKeyConstraint('id') ) - op.create_table('certificate_authorities', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('project_id', sa.String(length=36), nullable=False), - sa.Column('common_name', sa.String(length=255), nullable=False), - sa.Column('country', sa.String(length=2), nullable=True), - sa.Column('state', sa.String(length=255), nullable=True), - sa.Column('city', sa.String(length=255), nullable=True), - sa.Column('organization', sa.String(length=255), nullable=True), - sa.Column('organizational_unit', sa.String(length=255), nullable=True), - sa.Column('domain_name', sa.String(length=255), nullable=True), - sa.Column('validity_period', sa.Integer(), nullable=False), - sa.Column('is_active', sa.Boolean(), nullable=False), - sa.Column('private_key', mysql.LONGTEXT(), nullable=True), - sa.Column('certificate_data', mysql.LONGTEXT(), nullable=True), - sa.Column('serial_number', sa.String(length=255), nullable=True), - sa.Column('current_crl_id', sa.String(length=36), nullable=True), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('visible', sa.Boolean(), nullable=False), - sa.Column('name', sa.String(length=255), nullable=False), - sa.Column('description', mysql.LONGTEXT(), nullable=True), - sa.Column('status', sa.String(length=50), nullable=True), - sa.Column('created_by', sa.String(length=36), nullable=True), - sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), - sa.ForeignKeyConstraint(['current_crl_id'], ['certificate_revocation_lists.id'], name='fk_ca_current_crl', ondelete='SET NULL'), - sa.ForeignKeyConstraint(['project_id'], ['projects.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('project_id') - ) - op.create_table('region_access', - sa.Column('project_id', sa.String(length=36), nullable=False), - sa.Column('region_id', sa.String(length=36), nullable=False), - sa.ForeignKeyConstraint(['project_id'], ['projects.id'], ), - sa.ForeignKeyConstraint(['region_id'], ['regions.id'], ), - sa.PrimaryKeyConstraint('project_id', 'region_id') - ) - op.create_table('vdcs', - sa.Column('region_id', sa.String(length=36), nullable=False), - sa.Column('project_id', sa.String(length=36), nullable=False), + with op.batch_alter_table('workload_hosts', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_workload_hosts_tenant_id'), ['tenant_id'], unique=False) + + op.create_table('container_pods', + sa.Column('workload_host_id', sa.String(length=36), nullable=True), + sa.Column('region_id', sa.String(length=36), nullable=True), + sa.Column('allocation_attempts', sa.Integer(), nullable=False), + sa.Column('max_allocation_attempts', sa.Integer(), nullable=True), + sa.Column('next_retry_at', sa.DateTime(), nullable=True), + sa.Column('last_attempt_at', sa.DateTime(), nullable=True), + sa.Column('last_error_reason', sa.String(length=255), nullable=True), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), @@ -249,13 +328,45 @@ def upgrade(): sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('status', sa.String(length=50), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), - sa.ForeignKeyConstraint(['project_id'], ['projects.id'], ), + sa.ForeignKeyConstraint(['region_id'], ['regions.id'], ), + sa.ForeignKeyConstraint(['workload_host_id'], ['workload_hosts.id'], ), + sa.PrimaryKeyConstraint('id') + ) + with op.batch_alter_table('container_pods', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_container_pods_region_id'), ['region_id'], unique=False) + batch_op.create_index(batch_op.f('ix_container_pods_tenant_id'), ['tenant_id'], unique=False) + + op.create_table('host_failure_audit', + sa.Column('id', sa.String(length=36), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('region_id', sa.String(length=36), nullable=False), + sa.Column('host_id', sa.String(length=36), nullable=False), + sa.Column('event_type', sa.String(length=50), nullable=False), + sa.Column('window_count', sa.Integer(), nullable=True), + sa.Column('threshold', sa.Integer(), nullable=True), + sa.Column('decision', sa.String(length=50), nullable=False), + sa.Column('details', sa.JSON(), nullable=True), + sa.Column('visible', sa.Boolean(), nullable=False), + sa.Column('name', sa.String(length=255), nullable=False), + sa.Column('description', mysql.LONGTEXT(), nullable=True), + sa.Column('status', sa.String(length=50), nullable=True), + sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), + sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), + sa.Column('deleted', sa.Boolean(), nullable=False), + sa.ForeignKeyConstraint(['host_id'], ['workload_hosts.id'], ), sa.ForeignKeyConstraint(['region_id'], ['regions.id'], ), sa.PrimaryKeyConstraint('id') ) + with op.batch_alter_table('host_failure_audit', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_host_failure_audit_tenant_id'), ['tenant_id'], unique=False) + op.create_table('workload_host_available_ports', sa.Column('workload_host_id', sa.String(length=36), nullable=False), sa.Column('start_port', sa.Integer(), nullable=False), @@ -269,12 +380,16 @@ def upgrade(): sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('status', sa.String(length=50), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), sa.ForeignKeyConstraint(['workload_host_id'], ['workload_hosts.id'], ), sa.PrimaryKeyConstraint('id') ) + with op.batch_alter_table('workload_host_available_ports', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_workload_host_available_ports_tenant_id'), ['tenant_id'], unique=False) + op.create_table('workload_host_fixed_resources', sa.Column('type', sa.String(length=50), nullable=False), sa.Column('model', sa.String(length=255), nullable=True), @@ -289,12 +404,16 @@ def upgrade(): sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('status', sa.String(length=50), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), sa.ForeignKeyConstraint(['workload_host_id'], ['workload_hosts.id'], ), sa.PrimaryKeyConstraint('id') ) + with op.batch_alter_table('workload_host_fixed_resources', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_workload_host_fixed_resources_tenant_id'), ['tenant_id'], unique=False) + op.create_table('workload_host_ovs_bridge', sa.Column('workload_host_id', sa.String(length=36), nullable=False), sa.Column('ovs_bridge_name', sa.String(length=255), nullable=False), @@ -306,12 +425,16 @@ def upgrade(): sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('status', sa.String(length=50), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), sa.ForeignKeyConstraint(['workload_host_id'], ['workload_hosts.id'], ), sa.PrimaryKeyConstraint('id') ) + with op.batch_alter_table('workload_host_ovs_bridge', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_workload_host_ovs_bridge_tenant_id'), ['tenant_id'], unique=False) + op.create_table('workload_host_pooled_resources', sa.Column('workload_host_id', sa.String(length=36), nullable=False), sa.Column('resource_type', sa.String(length=50), nullable=False), @@ -326,56 +449,22 @@ def upgrade(): sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('status', sa.String(length=50), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), sa.ForeignKeyConstraint(['workload_host_id'], ['workload_hosts.id'], ), sa.PrimaryKeyConstraint('id') ) - op.create_table('certificates', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('ca_id', sa.String(length=36), nullable=False), - sa.Column('certificate_type', sa.String(length=50), nullable=False), - sa.Column('common_name', sa.String(length=255), nullable=False), - sa.Column('country', sa.String(length=2), nullable=True), - sa.Column('state', sa.String(length=255), nullable=True), - sa.Column('city', sa.String(length=255), nullable=True), - sa.Column('organization', sa.String(length=255), nullable=True), - sa.Column('organizational_unit', sa.String(length=255), nullable=True), - sa.Column('email', sa.String(length=255), nullable=True), - sa.Column('validity_period', sa.Integer(), nullable=False), - sa.Column('is_active', sa.Boolean(), nullable=False), - sa.Column('revoked', sa.Boolean(), nullable=False), - sa.Column('revoked_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('serial_number', sa.BigInteger(), nullable=True), - sa.Column('public_key', mysql.LONGTEXT(), nullable=True), - sa.Column('private_key', mysql.LONGTEXT(), nullable=True), - sa.Column('certificate_data', mysql.LONGTEXT(), nullable=True), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('visible', sa.Boolean(), nullable=False), - sa.Column('name', sa.String(length=255), nullable=False), - sa.Column('description', mysql.LONGTEXT(), nullable=True), - sa.Column('status', sa.String(length=50), nullable=True), - sa.Column('created_by', sa.String(length=36), nullable=True), - sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['ca_id'], ['certificate_authorities.id'], ondelete='CASCADE'), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('ca_id', 'serial_number', name='uq_cert_ca_serial') - ) - with op.batch_alter_table('certificates', schema=None) as batch_op: - batch_op.create_index('ix_cert_ca_serial', ['ca_id', 'serial_number'], unique=False) + with op.batch_alter_table('workload_host_pooled_resources', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_workload_host_pooled_resources_tenant_id'), ['tenant_id'], unique=False) - op.create_table('container_pods', - sa.Column('workload_host_id', sa.String(length=36), nullable=True), - sa.Column('vdc_id', sa.String(length=36), nullable=False), - sa.Column('allocation_attempts', sa.Integer(), nullable=False), - sa.Column('max_allocation_attempts', sa.Integer(), nullable=True), - sa.Column('next_retry_at', sa.DateTime(), nullable=True), - sa.Column('last_attempt_at', sa.DateTime(), nullable=True), - sa.Column('last_error_reason', sa.String(length=255), nullable=True), + op.create_table('pod_dns_records', + sa.Column('target_pod_id', sa.String(length=36), nullable=True), + sa.Column('custom_fqdn', sa.String(length=255), nullable=False), + sa.Column('record_type', sa.String(length=10), nullable=False), + sa.Column('target_value', sa.String(length=255), nullable=False), + sa.Column('ttl', sa.Integer(), nullable=False), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), @@ -384,82 +473,35 @@ def upgrade(): sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('status', sa.String(length=50), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), - sa.ForeignKeyConstraint(['vdc_id'], ['vdcs.id'], ), - sa.ForeignKeyConstraint(['workload_host_id'], ['workload_hosts.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_table('networks', - sa.Column('vdc_id', sa.String(length=36), nullable=False), - sa.Column('ipv4_cidr', sa.String(length=50), nullable=True), - sa.Column('ipv4_gateway', sa.String(length=50), nullable=True), - sa.Column('ipv4_dns_servers', sa.String(length=255), nullable=True), - sa.Column('ipv6_cidr', sa.String(length=50), nullable=True), - sa.Column('ipv6_gateway', sa.String(length=50), nullable=True), - sa.Column('vni', sa.Integer(), nullable=False), - sa.Column('encapsulation', sa.String(length=50), nullable=False), - sa.Column('ovs_bridge', sa.String(length=255), nullable=True), - sa.Column('network_type', sa.String(length=255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('visible', sa.Boolean(), nullable=False), - sa.Column('name', sa.String(length=255), nullable=False), - sa.Column('description', mysql.LONGTEXT(), nullable=True), - sa.Column('status', sa.String(length=50), nullable=True), - sa.Column('created_by', sa.String(length=36), nullable=True), - sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), - sa.ForeignKeyConstraint(['vdc_id'], ['vdcs.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_table('volumes', - sa.Column('path', sa.String(length=255), nullable=True), - sa.Column('type', sa.String(length=50), nullable=True), - sa.Column('source', sa.String(length=255), nullable=True), - sa.Column('size_gb', sa.Float(), nullable=False), - sa.Column('boot', sa.Boolean(), nullable=False), - sa.Column('vdc_id', sa.String(length=36), nullable=False), - sa.Column('image_id', sa.String(length=36), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('visible', sa.Boolean(), nullable=False), - sa.Column('name', sa.String(length=255), nullable=False), - sa.Column('description', mysql.LONGTEXT(), nullable=True), - sa.Column('status', sa.String(length=50), nullable=True), - sa.Column('created_by', sa.String(length=36), nullable=True), - sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), - sa.ForeignKeyConstraint(['image_id'], ['images.id'], ), - sa.ForeignKeyConstraint(['vdc_id'], ['vdcs.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_table('workload_requests', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('vdc_id', sa.String(length=36), nullable=False), - sa.Column('payload', sa.JSON(), nullable=False), - sa.Column('status', sa.String(length=32), nullable=True), - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('updated_at', sa.DateTime(), nullable=True), - sa.Column('workload_type', sa.String(length=32), nullable=True), - sa.ForeignKeyConstraint(['vdc_id'], ['vdcs.id'], ), + sa.ForeignKeyConstraint(['target_pod_id'], ['container_pods.id'], ), sa.PrimaryKeyConstraint('id') ) + with op.batch_alter_table('pod_dns_records', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_pod_dns_records_custom_fqdn'), ['custom_fqdn'], unique=False) + batch_op.create_index(batch_op.f('ix_pod_dns_records_target_pod_id'), ['target_pod_id'], unique=False) + batch_op.create_index(batch_op.f('ix_pod_dns_records_tenant_id'), ['tenant_id'], unique=False) + op.create_table('workloads', sa.Column('workload_host_id', sa.String(length=36), nullable=True), - sa.Column('vdc_id', sa.String(length=36), nullable=False), + sa.Column('region_id', sa.String(length=36), nullable=True), sa.Column('workload_type', sa.String(length=50), nullable=False), sa.Column('container_id', sa.String(length=255), nullable=True), sa.Column('launch_params', mysql.LONGTEXT(), nullable=True), sa.Column('time_to_provision', sa.Float(), nullable=True), sa.Column('is_sidecar', sa.Boolean(), nullable=False), sa.Column('extended_status', sa.String(length=1024), nullable=True), + sa.Column('allocation_attempts', sa.Integer(), nullable=False, server_default=sa.text('0')), + sa.Column('max_allocation_attempts', sa.Integer(), nullable=True), + sa.Column('next_retry_at', sa.DateTime(), nullable=True), + sa.Column('last_attempt_at', sa.DateTime(), nullable=True), + sa.Column('last_error_reason', sa.String(length=512), nullable=True), + sa.Column('excluded_host_ids', sa.JSON(), nullable=True), sa.Column('pod_id', sa.String(length=36), nullable=True), + sa.Column('server_group_id', sa.String(length=36), nullable=True), sa.Column('status', sa.String(length=50), nullable=True), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), @@ -468,37 +510,20 @@ def upgrade(): sa.Column('name', sa.String(length=255), nullable=False), sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), sa.ForeignKeyConstraint(['pod_id'], ['container_pods.id'], ), - sa.ForeignKeyConstraint(['vdc_id'], ['vdcs.id'], ), + sa.ForeignKeyConstraint(['region_id'], ['regions.id'], ), + sa.ForeignKeyConstraint(['server_group_id'], ['server_groups.id'], ), sa.ForeignKeyConstraint(['workload_host_id'], ['workload_hosts.id'], ), sa.PrimaryKeyConstraint('id') ) - op.create_table('cloudflare_tunnels', - sa.Column('account_id', sa.String(length=255), nullable=False), - sa.Column('tunnel_id', sa.String(length=255), nullable=False), - sa.Column('tunnel_secret', sa.String(length=255), nullable=False), - sa.Column('token', sa.String(length=255), nullable=False), - sa.Column('associated_hostname', sa.String(length=255), nullable=True), - sa.Column('notes', mysql.LONGTEXT(), nullable=True), - sa.Column('nscontroller_workload_id', sa.String(length=36), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('visible', sa.Boolean(), nullable=False), - sa.Column('name', sa.String(length=255), nullable=False), - sa.Column('description', mysql.LONGTEXT(), nullable=True), - sa.Column('status', sa.String(length=50), nullable=True), - sa.Column('created_by', sa.String(length=36), nullable=True), - sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), - sa.ForeignKeyConstraint(['nscontroller_workload_id'], ['workloads.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('tunnel_id') - ) + with op.batch_alter_table('workloads', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_workloads_region_id'), ['region_id'], unique=False) + batch_op.create_index(batch_op.f('ix_workloads_tenant_id'), ['tenant_id'], unique=False) + op.create_table('network_ports', sa.Column('network_id', sa.String(length=36), nullable=False), sa.Column('workload_id', sa.String(length=36), nullable=True), @@ -515,14 +540,60 @@ def upgrade(): sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('status', sa.String(length=50), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), sa.ForeignKeyConstraint(['network_id'], ['networks.id'], ), sa.ForeignKeyConstraint(['workload_id'], ['workloads.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name') ) + with op.batch_alter_table('network_ports', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_network_ports_tenant_id'), ['tenant_id'], unique=False) + + op.create_table('port_forwarding', + sa.Column('pod_id', sa.String(length=36), nullable=False), + sa.Column('internal_port', sa.Integer(), nullable=False), + sa.Column('external_port', sa.Integer(), nullable=False), + sa.Column('protocol', sa.String(length=10), nullable=False), + sa.Column('external_ip_address', sa.String(length=25), nullable=False), + sa.Column('internal_ip_address', sa.String(length=25), nullable=False), + sa.Column('use_dns', sa.Boolean(), nullable=False, server_default=sa.text('0')), + sa.Column('workload_id', sa.String(length=36), nullable=True), + sa.Column('id', sa.String(length=36), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('visible', sa.Boolean(), nullable=False), + sa.Column('name', sa.String(length=255), nullable=False), + sa.Column('description', mysql.LONGTEXT(), nullable=True), + sa.Column('status', sa.String(length=50), nullable=True), + sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), + sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), + sa.Column('deleted', sa.Boolean(), nullable=False), + sa.ForeignKeyConstraint(['pod_id'], ['container_pods.id'], ), + sa.ForeignKeyConstraint(['workload_id'], ['workloads.id'], ), + sa.PrimaryKeyConstraint('id') + ) + with op.batch_alter_table('port_forwarding', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_port_forwarding_tenant_id'), ['tenant_id'], unique=False) + + op.create_table('vm_metadata', + sa.Column('id', sa.String(length=36), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('workload_id', sa.String(length=36), nullable=False), + sa.Column('instance_id', sa.String(length=36), nullable=True), + sa.Column('hostname', sa.String(length=255), nullable=True), + sa.Column('local_hostname', sa.String(length=255), nullable=True), + sa.Column('public_keys', sa.JSON(), nullable=True), + sa.Column('user_data', mysql.LONGTEXT(), nullable=True), + sa.ForeignKeyConstraint(['workload_id'], ['workloads.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('workload_id') + ) op.create_table('volume_workload_mapping', sa.Column('volume_id', sa.String(length=36), nullable=False), sa.Column('workload_id', sa.String(length=36), nullable=False), @@ -534,13 +605,17 @@ def upgrade(): sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('status', sa.String(length=50), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), sa.ForeignKeyConstraint(['volume_id'], ['volumes.id'], ), sa.ForeignKeyConstraint(['workload_id'], ['workloads.id'], ), sa.PrimaryKeyConstraint('volume_id', 'workload_id', 'id') ) + with op.batch_alter_table('volume_workload_mapping', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_volume_workload_mapping_tenant_id'), ['tenant_id'], unique=False) + op.create_table('workload_host_port_mappings', sa.Column('id', sa.String(length=36), nullable=False), sa.Column('workload_host_id', sa.String(length=36), nullable=False), @@ -564,366 +639,120 @@ def upgrade(): sa.Column('description', mysql.LONGTEXT(), nullable=True), sa.Column('status', sa.String(length=50), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=True), + sa.Column('tenant_id', sa.String(length=255), nullable=False, server_default=sa.text("''")), + sa.Column('attributes', sa.JSON(), nullable=True), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), - sa.ForeignKeyConstraint(['workload_id'], ['workloads.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_table('cloudflare_dns_records', - sa.Column('zone_id', sa.String(length=255), nullable=False), - sa.Column('dns_record_id', sa.String(length=255), nullable=False), - sa.Column('hostname', sa.String(length=255), nullable=False), - sa.Column('record_type', sa.String(length=50), nullable=False), - sa.Column('content', sa.String(length=255), nullable=False), - sa.Column('ttl', sa.Integer(), nullable=True), - sa.Column('proxied', sa.Boolean(), nullable=True), - sa.Column('notes', mysql.LONGTEXT(), nullable=True), - sa.Column('tunnel_id', sa.String(length=36), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('visible', sa.Boolean(), nullable=False), - sa.Column('name', sa.String(length=255), nullable=False), - sa.Column('description', mysql.LONGTEXT(), nullable=True), - sa.Column('status', sa.String(length=50), nullable=True), - sa.Column('created_by', sa.String(length=36), nullable=True), - sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), - sa.ForeignKeyConstraint(['tunnel_id'], ['cloudflare_tunnels.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('dns_record_id') - ) - op.create_table('port_forwarding', - sa.Column('pod_id', sa.String(length=36), nullable=False), - sa.Column('internal_port', sa.Integer(), nullable=False), - sa.Column('external_port', sa.Integer(), nullable=False), - sa.Column('protocol', sa.String(length=10), nullable=False), - sa.Column('external_ip_address', sa.String(length=25), nullable=False), - sa.Column('internal_ip_address', sa.String(length=25), nullable=False), - sa.Column('dns_record_id', sa.String(length=36), nullable=True), - sa.Column('workload_id', sa.String(length=36), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('visible', sa.Boolean(), nullable=False), - sa.Column('name', sa.String(length=255), nullable=False), - sa.Column('description', mysql.LONGTEXT(), nullable=True), - sa.Column('status', sa.String(length=50), nullable=True), - sa.Column('created_by', sa.String(length=36), nullable=True), - sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), - sa.ForeignKeyConstraint(['dns_record_id'], ['cloudflare_dns_records.id'], ), - sa.ForeignKeyConstraint(['pod_id'], ['container_pods.id'], ), sa.ForeignKeyConstraint(['workload_id'], ['workloads.id'], ), sa.PrimaryKeyConstraint('id') ) + with op.batch_alter_table('workload_resource_usage', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_workload_resource_usage_tenant_id'), ['tenant_id'], unique=False) - # === From 5355aba46f23_schema_update.py === - op.create_table('host_failure_audit', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('region_id', sa.String(length=36), nullable=False), - sa.Column('host_id', sa.String(length=36), nullable=False), - sa.Column('event_type', sa.String(length=50), nullable=False), - sa.Column('window_count', sa.Integer(), nullable=True), - sa.Column('threshold', sa.Integer(), nullable=True), - sa.Column('decision', sa.String(length=50), nullable=False), - sa.Column('details', sa.JSON(), nullable=True), - sa.Column('visible', sa.Boolean(), nullable=False), - sa.Column('name', sa.String(length=255), nullable=False), - sa.Column('description', mysql.LONGTEXT(), nullable=True), - sa.Column('status', sa.String(length=50), nullable=True), - sa.Column('created_by', sa.String(length=36), nullable=True), - sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), - sa.ForeignKeyConstraint(['host_id'], ['workload_hosts.id'], ), - sa.ForeignKeyConstraint(['region_id'], ['regions.id'], ), - sa.PrimaryKeyConstraint('id') - ) - with op.batch_alter_table('regions', schema=None) as batch_op: - batch_op.add_column(sa.Column('max_host_failures', sa.Integer(), nullable=False)) - batch_op.add_column(sa.Column('failure_time_window', sa.Integer(), nullable=False)) - batch_op.add_column(sa.Column('relocate_on_host_failure', sa.Boolean(), nullable=False)) - batch_op.add_column(sa.Column('host_failure_reallocation_delay', sa.Integer(), nullable=False)) - batch_op.add_column(sa.Column('failover_paused', sa.Boolean(), nullable=False)) - batch_op.add_column(sa.Column('pause_reason', sa.String(length=255), nullable=True)) - batch_op.add_column(sa.Column('pause_started_at', sa.DateTime(timezone=True), nullable=True)) - - # === From eadc45347e95_dns.py === - op.create_table('pod_dns_records', - sa.Column('vdc_id', sa.String(length=36), nullable=False), - sa.Column('target_pod_id', sa.String(length=36), nullable=True), - sa.Column('custom_fqdn', sa.String(length=255), nullable=False), - sa.Column('record_type', sa.String(length=10), nullable=False), - sa.Column('target_value', sa.String(length=255), nullable=False), - sa.Column('ttl', sa.Integer(), nullable=False), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('visible', sa.Boolean(), nullable=False), - sa.Column('name', sa.String(length=255), nullable=False), - sa.Column('description', mysql.LONGTEXT(), nullable=True), - sa.Column('status', sa.String(length=50), nullable=True), - sa.Column('created_by', sa.String(length=36), nullable=True), - sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('deleted', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), - sa.ForeignKeyConstraint(['target_pod_id'], ['container_pods.id'], ), - sa.ForeignKeyConstraint(['vdc_id'], ['vdcs.id'], ), - sa.PrimaryKeyConstraint('id') - ) - with op.batch_alter_table('pod_dns_records', schema=None) as batch_op: - batch_op.create_index(batch_op.f('ix_pod_dns_records_custom_fqdn'), ['custom_fqdn'], unique=False) - batch_op.create_index(batch_op.f('ix_pod_dns_records_target_pod_id'), ['target_pod_id'], unique=False) - batch_op.create_index(batch_op.f('ix_pod_dns_records_vdc_id'), ['vdc_id'], unique=False) - - with op.batch_alter_table('universes', schema=None) as batch_op: - batch_op.add_column(sa.Column('universe_dns_name', sa.String(length=255), nullable=False)) - - # === From 75bed14faf79_add_ovs_fallback.py === - with op.batch_alter_table('regions', schema=None) as batch_op: - batch_op.add_column(sa.Column('default_ovs_bridge', sa.String(length=255), nullable=True)) - - # === From a1b2c3d4e5f6_add_server_groups.py === - op.create_table( - "server_groups", - sa.Column("id", sa.String(36), primary_key=True), - sa.Column("created_at", sa.DateTime, nullable=False, server_default=sa.func.now()), - sa.Column("updated_at", sa.DateTime, nullable=False, server_default=sa.func.now()), - sa.Column("deleted_at", sa.DateTime, nullable=True), - sa.Column("deleted", sa.Boolean, nullable=False, server_default=sa.text("0")), - sa.Column("visible", sa.Boolean, nullable=False, server_default=sa.text("1")), - sa.Column("name", sa.String(255), nullable=False, server_default=""), - sa.Column("description", sa.Text, nullable=True), - sa.Column("status", sa.String(50), nullable=True), - sa.Column("created_by", sa.String(36), sa.ForeignKey("users.id"), nullable=True), - sa.Column("vdc_id", sa.String(36), sa.ForeignKey("vdcs.id"), nullable=False), - sa.Column("policy", sa.String(50), nullable=False, server_default="soft-affinity"), - ) - - op.add_column( - "workloads", - sa.Column("server_group_id", sa.String(36), sa.ForeignKey("server_groups.id"), nullable=True), - ) - - # === From f1a2b3c4d5e6_add_network_dhcp_nsctrl_fields.py === - with op.batch_alter_table('networks', schema=None) as batch_op: - batch_op.add_column(sa.Column('dhcp_range_start', sa.String(length=50), nullable=True)) - batch_op.add_column(sa.Column('dhcp_range_end', sa.String(length=50), nullable=True)) - batch_op.add_column(sa.Column('nscontroller_ip', sa.String(length=50), nullable=True)) - - # === From d4e5f6a1b2c3_add_vm_metadata_table.py === - bind = op.get_bind() - inspector = inspect(bind) - if 'vm_metadata' not in inspector.get_table_names(): - op.create_table( - 'vm_metadata', - sa.Column('id', sa.String(36), primary_key=True), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('instance_id', sa.String(36), nullable=True), - sa.Column('hostname', sa.String(255), nullable=True), - sa.Column('local_hostname', sa.String(255), nullable=True), - sa.Column('public_keys', sa.JSON(), nullable=True), - sa.Column('user_data', mysql.LONGTEXT(), nullable=True), - sa.Column('workload_id', sa.String(36), sa.ForeignKey('workloads.id'), nullable=False, unique=True), - ) - op.create_index('ix_vm_metadata_workload_id', 'vm_metadata', ['workload_id'], unique=True) - - # === From cde7551c059a_fix_image_location_type_local_to_image.py === - op.execute( - "UPDATE images SET location_type = 'image' WHERE LOWER(location_type) = 'local'" - ) - - # === From 46d87a190aee_add_pci_device_filters_to_regions.py === - conn = op.get_bind() - cols = [row[0] for row in conn.execute(sa.text("SHOW COLUMNS FROM regions")).fetchall()] - if 'pci_device_filters' not in cols: - with op.batch_alter_table('regions', schema=None) as batch_op: - batch_op.add_column(sa.Column('pci_device_filters', sa.JSON(), nullable=True)) - - op.execute( - f"UPDATE regions SET pci_device_filters = '{DEFAULT_PCI_FILTERS}' WHERE pci_device_filters IS NULL" - ) - - # === From b2c3d4e5f6a7_add_gpu_tables.py === - op.create_table( - 'gpu_models', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('visible', sa.Boolean(), nullable=False), - sa.Column('name', sa.String(length=255), nullable=False), - sa.Column('description', mysql.LONGTEXT(), nullable=True), - sa.Column('status', sa.String(length=50), nullable=True), - sa.Column('created_by', sa.String(length=36), nullable=True), - sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('deleted', sa.Boolean(), nullable=False), - sa.Column('vendor_id', sa.String(length=10), nullable=True), - sa.Column('device_id', sa.String(length=10), nullable=True), - sa.Column('vendor_name', sa.String(length=100), nullable=True), - sa.Column('device_name', sa.String(length=200), nullable=True), - sa.Column('vram_mb', sa.Integer(), nullable=True), - sa.Column('architecture', sa.String(length=100), nullable=True), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_table( - 'host_gpus', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('visible', sa.Boolean(), nullable=False), - sa.Column('name', sa.String(length=255), nullable=False), - sa.Column('description', mysql.LONGTEXT(), nullable=True), - sa.Column('status', sa.String(length=50), nullable=True), - sa.Column('created_by', sa.String(length=36), nullable=True), - sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('deleted', sa.Boolean(), nullable=False), - sa.Column('gpu_model_id', sa.String(length=36), nullable=False), - sa.Column('pci_address', sa.String(length=100), nullable=False), - sa.Column('workload_host_id', sa.String(length=36), nullable=True), - sa.Column('gpu_status', sa.String(length=50), nullable=False, server_default='available'), - sa.Column('assigned_workload_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), - sa.ForeignKeyConstraint(['gpu_model_id'], ['gpu_models.id'], ), - sa.ForeignKeyConstraint(['workload_host_id'], ['workload_hosts.id'], ), - sa.ForeignKeyConstraint(['assigned_workload_id'], ['workloads.id'], ), - sa.PrimaryKeyConstraint('id') - ) - - # === From b2c3d4e5f6a1_add_ssh_keys.py === - bind = op.get_bind() - inspector = inspect(bind) - existing_tables = inspector.get_table_names() - - if 'ssh_keys' not in existing_tables: - op.create_table( - 'ssh_keys', - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('user_id', sa.String(length=36), nullable=True), - sa.Column('key_name', sa.String(length=255), nullable=False), - sa.Column('public_key_data', sa.Text(), nullable=False), - sa.Column('key_fingerprint', sa.String(length=255), nullable=True), - sa.Column('is_default', sa.Boolean(), nullable=False, server_default=sa.false()), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=False), - sa.Column('deleted', sa.Boolean(), nullable=False, server_default=sa.false()), - sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id'), - ) - with op.batch_alter_table('ssh_keys', schema=None) as batch_op: - batch_op.create_index(batch_op.f('ix_ssh_keys_user_id'), ['user_id'], unique=False) - else: - existing_columns = {col['name'] for col in inspector.get_columns('ssh_keys')} - - column_defs = { - 'user_id': sa.Column('user_id', sa.String(36), nullable=True), - 'key_name': sa.Column('key_name', sa.String(255), nullable=True), - 'public_key_data': sa.Column('public_key_data', sa.Text(), nullable=True), - 'key_fingerprint': sa.Column('key_fingerprint', sa.String(255), nullable=True), - 'is_default': sa.Column('is_default', sa.Boolean(), nullable=False, server_default=sa.false()), - 'created_at': sa.Column('created_at', sa.DateTime(), nullable=True), - 'updated_at': sa.Column('updated_at', sa.DateTime(), nullable=True), - 'deleted': sa.Column('deleted', sa.Boolean(), nullable=False, server_default=sa.false()), - 'deleted_at': sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), - } - - with op.batch_alter_table('ssh_keys', schema=None) as batch_op: - for col_name, col_def in column_defs.items(): - if col_name not in existing_columns: - batch_op.add_column(col_def) - - existing_indexes = {idx['name'] for idx in inspector.get_indexes('ssh_keys')} - if 'ix_ssh_keys_user_id' not in existing_indexes: - batch_op.create_index(batch_op.f('ix_ssh_keys_user_id'), ['user_id'], unique=False) + # host_gpus declares these only as comments in the model, but every + # database built by the old chain has them. Added last because host_gpus + # is created before the tables it points at. + op.create_foreign_key(None, 'host_gpus', 'workload_hosts', ['workload_host_id'], ['id']) + op.create_foreign_key(None, 'host_gpus', 'workloads', ['assigned_workload_id'], ['id']) def downgrade(): - # Reverse order of upgrade — dependencies must be removed before their parents + with op.batch_alter_table('workload_resource_usage', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_workload_resource_usage_tenant_id')) - op.drop_table('host_gpus') - op.drop_table('gpu_models') - - with op.batch_alter_table('ssh_keys', schema=None) as batch_op: - batch_op.drop_index(batch_op.f('ix_ssh_keys_user_id')) - op.drop_table('ssh_keys') - - with op.batch_alter_table('regions', schema=None) as batch_op: - batch_op.drop_column('pci_device_filters') + op.drop_table('workload_resource_usage') + op.drop_table('workload_host_port_mappings') + with op.batch_alter_table('volume_workload_mapping', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_volume_workload_mapping_tenant_id')) + op.drop_table('volume_workload_mapping') op.drop_table('vm_metadata') + with op.batch_alter_table('port_forwarding', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_port_forwarding_tenant_id')) - with op.batch_alter_table('networks', schema=None) as batch_op: - batch_op.drop_column('nscontroller_ip') - batch_op.drop_column('dhcp_range_end') - batch_op.drop_column('dhcp_range_start') + op.drop_table('port_forwarding') + with op.batch_alter_table('network_ports', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_network_ports_tenant_id')) - # Must remove workloads.server_group_id FK before dropping server_groups + op.drop_table('network_ports') with op.batch_alter_table('workloads', schema=None) as batch_op: - batch_op.drop_column('server_group_id') - - op.drop_table('server_groups') - - with op.batch_alter_table('regions', schema=None) as batch_op: - batch_op.drop_column('default_ovs_bridge') + batch_op.drop_index(batch_op.f('ix_workloads_tenant_id')) + batch_op.drop_index(batch_op.f('ix_workloads_region_id')) + op.drop_table('workloads') with op.batch_alter_table('pod_dns_records', schema=None) as batch_op: - batch_op.drop_index(batch_op.f('ix_pod_dns_records_vdc_id')) + batch_op.drop_index(batch_op.f('ix_pod_dns_records_tenant_id')) batch_op.drop_index(batch_op.f('ix_pod_dns_records_target_pod_id')) batch_op.drop_index(batch_op.f('ix_pod_dns_records_custom_fqdn')) op.drop_table('pod_dns_records') + with op.batch_alter_table('workload_host_pooled_resources', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_workload_host_pooled_resources_tenant_id')) - with op.batch_alter_table('universes', schema=None) as batch_op: - batch_op.drop_column('universe_dns_name') + op.drop_table('workload_host_pooled_resources') + with op.batch_alter_table('workload_host_ovs_bridge', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_workload_host_ovs_bridge_tenant_id')) - with op.batch_alter_table('regions', schema=None) as batch_op: - batch_op.drop_column('pause_started_at') - batch_op.drop_column('pause_reason') - batch_op.drop_column('failover_paused') - batch_op.drop_column('host_failure_reallocation_delay') - batch_op.drop_column('relocate_on_host_failure') - batch_op.drop_column('failure_time_window') - batch_op.drop_column('max_host_failures') + op.drop_table('workload_host_ovs_bridge') + with op.batch_alter_table('workload_host_fixed_resources', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_workload_host_fixed_resources_tenant_id')) + + op.drop_table('workload_host_fixed_resources') + with op.batch_alter_table('workload_host_available_ports', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_workload_host_available_ports_tenant_id')) + + op.drop_table('workload_host_available_ports') + with op.batch_alter_table('host_failure_audit', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_host_failure_audit_tenant_id')) op.drop_table('host_failure_audit') - op.drop_table('port_forwarding') - op.drop_table('cloudflare_dns_records') - op.drop_table('workload_resource_usage') - op.drop_table('workload_host_port_mappings') - op.drop_table('volume_workload_mapping') - op.drop_table('network_ports') - op.drop_table('cloudflare_tunnels') - op.drop_table('workloads') - op.drop_table('workload_requests') - op.drop_table('volumes') - op.drop_table('networks') + with op.batch_alter_table('container_pods', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_container_pods_tenant_id')) + batch_op.drop_index(batch_op.f('ix_container_pods_region_id')) + op.drop_table('container_pods') + with op.batch_alter_table('workload_hosts', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_workload_hosts_tenant_id')) - with op.batch_alter_table('certificates', schema=None) as batch_op: - batch_op.drop_index('ix_cert_ca_serial') - - op.drop_table('certificates') - op.drop_table('workload_host_pooled_resources') - op.drop_table('workload_host_ovs_bridge') - op.drop_table('workload_host_fixed_resources') - op.drop_table('workload_host_available_ports') - op.drop_table('vdcs') - op.drop_table('region_access') - op.drop_table('certificate_authorities') op.drop_table('workload_hosts') - op.drop_table('projects') - op.drop_table('universes') + with op.batch_alter_table('volumes', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_volumes_tenant_id')) + + op.drop_table('volumes') + with op.batch_alter_table('networks', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_networks_tenant_id')) + + op.drop_table('networks') + with op.batch_alter_table('host_gpus', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_host_gpus_tenant_id')) + + op.drop_table('host_gpus') + with op.batch_alter_table('workload_requests', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_workload_requests_tenant_id')) + + op.drop_table('workload_requests') + with op.batch_alter_table('tasks', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_tasks_worker_id')) + + op.drop_table('tasks') + with op.batch_alter_table('server_groups', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_server_groups_tenant_id')) + + op.drop_table('server_groups') + with op.batch_alter_table('regions', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_regions_tenant_id')) + op.drop_table('regions') + with op.batch_alter_table('labels', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_labels_tenant_id')) + op.drop_table('labels') + with op.batch_alter_table('images', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_images_tenant_id')) + op.drop_table('images') - op.drop_table('certificate_revocation_lists') + with op.batch_alter_table('gpu_models', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_gpu_models_tenant_id')) + + op.drop_table('gpu_models') op.drop_table('audit_entry') - op.drop_table('users') diff --git a/core/migrations/versions/0001_workload_vm_retry_fields.py b/core/migrations/versions/0001_workload_vm_retry_fields.py deleted file mode 100644 index 221147c..0000000 --- a/core/migrations/versions/0001_workload_vm_retry_fields.py +++ /dev/null @@ -1,31 +0,0 @@ -"""Add VM scheduling retry fields to workloads table - -Revision ID: 0001_workload_vm_retry_fields -Revises: 0000_merged_all_migrations -Create Date: 2026-06-07 -""" -from alembic import op -import sqlalchemy as sa - -revision = '0001_workload_vm_retry_fields' -down_revision = '0000_merged_all_migrations' -branch_labels = None -depends_on = None - - -def upgrade(): - with op.batch_alter_table('workloads', schema=None) as batch_op: - batch_op.add_column(sa.Column('allocation_attempts', sa.Integer(), nullable=False, server_default='0')) - batch_op.add_column(sa.Column('max_allocation_attempts', sa.Integer(), nullable=True)) - batch_op.add_column(sa.Column('next_retry_at', sa.DateTime(), nullable=True)) - batch_op.add_column(sa.Column('last_attempt_at', sa.DateTime(), nullable=True)) - batch_op.add_column(sa.Column('last_error_reason', sa.String(255), nullable=True)) - - -def downgrade(): - with op.batch_alter_table('workloads', schema=None) as batch_op: - batch_op.drop_column('last_error_reason') - batch_op.drop_column('last_attempt_at') - batch_op.drop_column('next_retry_at') - batch_op.drop_column('max_allocation_attempts') - batch_op.drop_column('allocation_attempts') diff --git a/core/migrations/versions/0002_workload_excluded_hosts.py b/core/migrations/versions/0002_workload_excluded_hosts.py deleted file mode 100644 index 4f65082..0000000 --- a/core/migrations/versions/0002_workload_excluded_hosts.py +++ /dev/null @@ -1,23 +0,0 @@ -"""Add excluded_host_ids to workloads for retry host exclusion - -Revision ID: 0002_workload_excluded_hosts -Revises: 0001_workload_vm_retry_fields -Create Date: 2026-06-11 -""" -from alembic import op -import sqlalchemy as sa - -revision = '0002_workload_excluded_hosts' -down_revision = '0001_workload_vm_retry_fields' -branch_labels = None -depends_on = None - - -def upgrade(): - with op.batch_alter_table('workloads', schema=None) as batch_op: - batch_op.add_column(sa.Column('excluded_host_ids', sa.JSON(), nullable=True)) - - -def downgrade(): - with op.batch_alter_table('workloads', schema=None) as batch_op: - batch_op.drop_column('excluded_host_ids') diff --git a/core/migrations/versions/0003_network_enable_host_nat.py b/core/migrations/versions/0003_network_enable_host_nat.py deleted file mode 100644 index 8cf8ebc..0000000 --- a/core/migrations/versions/0003_network_enable_host_nat.py +++ /dev/null @@ -1,23 +0,0 @@ -"""Add enable_host_nat to networks for NSController internet egress via NAT - -Revision ID: 0003_network_enable_host_nat -Revises: 0002_workload_excluded_hosts -Create Date: 2026-08-08 -""" -from alembic import op -import sqlalchemy as sa - -revision = '0003_network_enable_host_nat' -down_revision = '0002_workload_excluded_hosts' -branch_labels = None -depends_on = None - - -def upgrade(): - with op.batch_alter_table('networks', schema=None) as batch_op: - batch_op.add_column(sa.Column('enable_host_nat', sa.Boolean(), nullable=False, server_default='0')) - - -def downgrade(): - with op.batch_alter_table('networks', schema=None) as batch_op: - batch_op.drop_column('enable_host_nat') diff --git a/core/migrations/versions/0008_drop_audit_user_id.py b/core/migrations/versions/0008_drop_audit_user_id.py new file mode 100644 index 0000000..b766b9e --- /dev/null +++ b/core/migrations/versions/0008_drop_audit_user_id.py @@ -0,0 +1,23 @@ +"""Drop audit_entry.user_id. + +Core has no users: the only credential it accepts is XCLOUDIFY_API_KEY, so +there is no actor to record. The column was filled from a JWT that no plane +sends to core any more. +""" +from alembic import op +import sqlalchemy as sa + +revision = '0008_drop_audit_user_id' +down_revision = '0007_cloudflare_out' +branch_labels = None +depends_on = None + + +def upgrade(): + columns = [c['name'] for c in sa.inspect(op.get_bind()).get_columns('audit_entry')] + if 'user_id' in columns: + op.drop_column('audit_entry', 'user_id') + + +def downgrade(): + op.add_column('audit_entry', sa.Column('user_id', sa.String(length=36), nullable=True))