Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
"""add agent device models

Revision ID: fccc870bdf4d
Revises: 30a1bcac4c80
Create Date: 2026-05-29 20:16:36.189898

"""
from collections.abc import Sequence

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = 'fccc870bdf4d'
down_revision: str | Sequence[str] | None = '30a1bcac4c80'
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('agent_device_instances',
sa.Column('workspace_id', sa.String(length=36), nullable=False),
sa.Column('preset_id', sa.String(length=128), nullable=False),
sa.Column('provider_id', sa.String(length=128), nullable=False),
sa.Column('display_name', sa.String(length=128), nullable=False),
sa.Column('hex_q', sa.Integer(), nullable=False),
sa.Column('hex_r', sa.Integer(), nullable=False),
sa.Column('status', sa.String(length=32), server_default='available', nullable=False),
sa.Column('status_reason', sa.String(length=128), nullable=True),
sa.Column('config', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('created_by', sa.String(length=36), nullable=True),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['workspace_id'], ['workspaces.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_agent_device_instances_deleted_at'), 'agent_device_instances', ['deleted_at'], unique=False)
op.create_index(op.f('ix_agent_device_instances_preset_id'), 'agent_device_instances', ['preset_id'], unique=False)
op.create_index(op.f('ix_agent_device_instances_provider_id'), 'agent_device_instances', ['provider_id'], unique=False)
op.create_index(op.f('ix_agent_device_instances_workspace_id'), 'agent_device_instances', ['workspace_id'], unique=False)
op.create_index('uq_agent_device_instance_hex', 'agent_device_instances', ['workspace_id', 'hex_q', 'hex_r'], unique=True, postgresql_where=sa.text('deleted_at IS NULL'))
op.create_table('agent_device_preset_enablements',
sa.Column('workspace_id', sa.String(length=36), nullable=False),
sa.Column('preset_id', sa.String(length=128), nullable=False),
sa.Column('enabled', sa.Boolean(), server_default='true', nullable=False),
sa.Column('config', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('created_by', sa.String(length=36), nullable=True),
sa.Column('updated_by', sa.String(length=36), nullable=True),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['workspace_id'], ['workspaces.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_agent_device_preset_enablements_deleted_at'), 'agent_device_preset_enablements', ['deleted_at'], unique=False)
op.create_index(op.f('ix_agent_device_preset_enablements_preset_id'), 'agent_device_preset_enablements', ['preset_id'], unique=False)
op.create_index(op.f('ix_agent_device_preset_enablements_workspace_id'), 'agent_device_preset_enablements', ['workspace_id'], unique=False)
op.create_index('uq_agent_device_preset_enablement', 'agent_device_preset_enablements', ['workspace_id', 'preset_id'], unique=True, postgresql_where=sa.text('deleted_at IS NULL'))
op.create_table('agent_device_grants',
sa.Column('workspace_id', sa.String(length=36), nullable=False),
sa.Column('device_id', sa.String(length=36), nullable=False),
sa.Column('subject_type', sa.String(length=16), nullable=False),
sa.Column('subject_id', sa.String(length=36), nullable=False),
sa.Column('scopes', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'[]'::jsonb"), nullable=False),
sa.Column('can_delegate', sa.Boolean(), server_default='false', nullable=False),
sa.Column('parent_grant_id', sa.String(length=36), nullable=True),
sa.Column('granted_by_type', sa.String(length=16), nullable=False),
sa.Column('granted_by_id', sa.String(length=36), nullable=False),
sa.Column('expires_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('revoked_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['device_id'], ['agent_device_instances.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['parent_grant_id'], ['agent_device_grants.id'], ),
sa.ForeignKeyConstraint(['workspace_id'], ['workspaces.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_agent_device_grants_deleted_at'), 'agent_device_grants', ['deleted_at'], unique=False)
op.create_index(op.f('ix_agent_device_grants_device_id'), 'agent_device_grants', ['device_id'], unique=False)
op.create_index('ix_agent_device_grants_parent', 'agent_device_grants', ['parent_grant_id'], unique=False)
op.create_index('ix_agent_device_grants_subject', 'agent_device_grants', ['workspace_id', 'subject_type', 'subject_id'], unique=False)
op.create_index(op.f('ix_agent_device_grants_subject_id'), 'agent_device_grants', ['subject_id'], unique=False)
op.create_index(op.f('ix_agent_device_grants_workspace_id'), 'agent_device_grants', ['workspace_id'], unique=False)
op.create_table('agent_device_leases',
sa.Column('workspace_id', sa.String(length=36), nullable=False),
sa.Column('device_id', sa.String(length=36), nullable=False),
sa.Column('holder_agent_id', sa.String(length=36), nullable=False),
sa.Column('grant_id', sa.String(length=36), nullable=False),
sa.Column('status', sa.String(length=16), server_default='active', nullable=False),
sa.Column('expires_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('renewed_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('released_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['device_id'], ['agent_device_instances.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['grant_id'], ['agent_device_grants.id'], ),
sa.ForeignKeyConstraint(['workspace_id'], ['workspaces.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_agent_device_leases_deleted_at'), 'agent_device_leases', ['deleted_at'], unique=False)
op.create_index(op.f('ix_agent_device_leases_device_id'), 'agent_device_leases', ['device_id'], unique=False)
op.create_index(op.f('ix_agent_device_leases_grant_id'), 'agent_device_leases', ['grant_id'], unique=False)
op.create_index('ix_agent_device_leases_holder', 'agent_device_leases', ['workspace_id', 'holder_agent_id'], unique=False)
op.create_index(op.f('ix_agent_device_leases_holder_agent_id'), 'agent_device_leases', ['holder_agent_id'], unique=False)
op.create_index(op.f('ix_agent_device_leases_workspace_id'), 'agent_device_leases', ['workspace_id'], unique=False)
op.create_index('uq_agent_device_active_lease', 'agent_device_leases', ['device_id'], unique=True, postgresql_where=sa.text("deleted_at IS NULL AND status = 'active'"))
op.create_table('agent_device_gene_bindings',
sa.Column('workspace_id', sa.String(length=36), nullable=False),
sa.Column('device_id', sa.String(length=36), nullable=False),
sa.Column('instance_id', sa.String(length=36), nullable=False),
sa.Column('gene_id', sa.String(length=36), nullable=True),
sa.Column('gene_slug', sa.String(length=128), nullable=False),
sa.Column('instance_gene_id', sa.String(length=36), nullable=True),
sa.Column('was_preexisting', sa.Boolean(), server_default='false', nullable=False),
sa.Column('sync_reason', sa.String(length=64), nullable=True),
sa.Column('metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['device_id'], ['agent_device_instances.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['gene_id'], ['genes.id'], ),
sa.ForeignKeyConstraint(['instance_gene_id'], ['instance_genes.id'], ),
sa.ForeignKeyConstraint(['instance_id'], ['instances.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['workspace_id'], ['workspaces.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_agent_device_gene_bindings_deleted_at'), 'agent_device_gene_bindings', ['deleted_at'], unique=False)
op.create_index(op.f('ix_agent_device_gene_bindings_device_id'), 'agent_device_gene_bindings', ['device_id'], unique=False)
op.create_index(op.f('ix_agent_device_gene_bindings_gene_slug'), 'agent_device_gene_bindings', ['gene_slug'], unique=False)
op.create_index(op.f('ix_agent_device_gene_bindings_instance_id'), 'agent_device_gene_bindings', ['instance_id'], unique=False)
op.create_index(op.f('ix_agent_device_gene_bindings_workspace_id'), 'agent_device_gene_bindings', ['workspace_id'], unique=False)
op.create_index('uq_agent_device_gene_binding', 'agent_device_gene_bindings', ['workspace_id', 'device_id', 'instance_id', 'gene_slug'], unique=True, postgresql_where=sa.text('deleted_at IS NULL'))
# ### end Alembic commands ###


def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index('uq_agent_device_gene_binding', table_name='agent_device_gene_bindings', postgresql_where=sa.text('deleted_at IS NULL'))
op.drop_index(op.f('ix_agent_device_gene_bindings_workspace_id'), table_name='agent_device_gene_bindings')
op.drop_index(op.f('ix_agent_device_gene_bindings_instance_id'), table_name='agent_device_gene_bindings')
op.drop_index(op.f('ix_agent_device_gene_bindings_gene_slug'), table_name='agent_device_gene_bindings')
op.drop_index(op.f('ix_agent_device_gene_bindings_device_id'), table_name='agent_device_gene_bindings')
op.drop_index(op.f('ix_agent_device_gene_bindings_deleted_at'), table_name='agent_device_gene_bindings')
op.drop_table('agent_device_gene_bindings')
op.drop_index('uq_agent_device_active_lease', table_name='agent_device_leases', postgresql_where=sa.text("deleted_at IS NULL AND status = 'active'"))
op.drop_index(op.f('ix_agent_device_leases_workspace_id'), table_name='agent_device_leases')
op.drop_index(op.f('ix_agent_device_leases_holder_agent_id'), table_name='agent_device_leases')
op.drop_index('ix_agent_device_leases_holder', table_name='agent_device_leases')
op.drop_index(op.f('ix_agent_device_leases_grant_id'), table_name='agent_device_leases')
op.drop_index(op.f('ix_agent_device_leases_device_id'), table_name='agent_device_leases')
op.drop_index(op.f('ix_agent_device_leases_deleted_at'), table_name='agent_device_leases')
op.drop_table('agent_device_leases')
op.drop_index(op.f('ix_agent_device_grants_workspace_id'), table_name='agent_device_grants')
op.drop_index(op.f('ix_agent_device_grants_subject_id'), table_name='agent_device_grants')
op.drop_index('ix_agent_device_grants_subject', table_name='agent_device_grants')
op.drop_index('ix_agent_device_grants_parent', table_name='agent_device_grants')
op.drop_index(op.f('ix_agent_device_grants_device_id'), table_name='agent_device_grants')
op.drop_index(op.f('ix_agent_device_grants_deleted_at'), table_name='agent_device_grants')
op.drop_table('agent_device_grants')
op.drop_index('uq_agent_device_preset_enablement', table_name='agent_device_preset_enablements', postgresql_where=sa.text('deleted_at IS NULL'))
op.drop_index(op.f('ix_agent_device_preset_enablements_workspace_id'), table_name='agent_device_preset_enablements')
op.drop_index(op.f('ix_agent_device_preset_enablements_preset_id'), table_name='agent_device_preset_enablements')
op.drop_index(op.f('ix_agent_device_preset_enablements_deleted_at'), table_name='agent_device_preset_enablements')
op.drop_table('agent_device_preset_enablements')
op.drop_index('uq_agent_device_instance_hex', table_name='agent_device_instances', postgresql_where=sa.text('deleted_at IS NULL'))
op.drop_index(op.f('ix_agent_device_instances_workspace_id'), table_name='agent_device_instances')
op.drop_index(op.f('ix_agent_device_instances_provider_id'), table_name='agent_device_instances')
op.drop_index(op.f('ix_agent_device_instances_preset_id'), table_name='agent_device_instances')
op.drop_index(op.f('ix_agent_device_instances_deleted_at'), table_name='agent_device_instances')
op.drop_table('agent_device_instances')
# ### end Alembic commands ###
Loading
Loading