feat(gateways): Introduce gateway model and update agent provisioning templates

This commit is contained in:
Abhimanyu Saharan
2026-02-04 23:07:22 +05:30
parent 1297c12a73
commit b6f31fe6ea
32 changed files with 2770 additions and 724 deletions

View File

@@ -0,0 +1,95 @@
"""Rename gateways to gateway.
Revision ID: 4b2a5e2dbb6e
Revises: c1c8b3b9f4d1
Create Date: 2026-02-04 18:20:00.000000
"""
from alembic import op
import sqlalchemy as sa
import sqlmodel
revision = "4b2a5e2dbb6e"
down_revision = "c1c8b3b9f4d1"
branch_labels = None
depends_on = None
def upgrade() -> None:
bind = op.get_bind()
inspector = sa.inspect(bind)
tables = set(inspector.get_table_names())
if "gateway_configs" in tables and "gateways" not in tables:
op.rename_table("gateway_configs", "gateways")
tables.discard("gateway_configs")
tables.add("gateways")
if "boards" in tables:
columns = {col["name"] for col in inspector.get_columns("boards")}
with op.batch_alter_table("boards") as batch:
if "gateway_config_id" in columns and "gateway_id" not in columns:
batch.alter_column(
"gateway_config_id",
new_column_name="gateway_id",
existing_type=sa.Uuid(),
)
elif "gateway_id" not in columns:
batch.add_column(sa.Column("gateway_id", sa.Uuid(), nullable=True))
for legacy_col in (
"gateway_url",
"gateway_token",
"gateway_main_session_key",
"gateway_workspace_root",
):
if legacy_col in columns:
batch.drop_column(legacy_col)
indexes = {index["name"] for index in inspector.get_indexes("boards")}
if "ix_boards_gateway_id" not in indexes:
op.create_index(
op.f("ix_boards_gateway_id"), "boards", ["gateway_id"], unique=False
)
def downgrade() -> None:
bind = op.get_bind()
inspector = sa.inspect(bind)
tables = set(inspector.get_table_names())
if "boards" in tables:
columns = {col["name"] for col in inspector.get_columns("boards")}
with op.batch_alter_table("boards") as batch:
if "gateway_id" in columns and "gateway_config_id" not in columns:
batch.alter_column(
"gateway_id",
new_column_name="gateway_config_id",
existing_type=sa.Uuid(),
)
if "gateway_url" not in columns:
batch.add_column(
sa.Column("gateway_url", sqlmodel.sql.sqltypes.AutoString(), nullable=True)
)
if "gateway_token" not in columns:
batch.add_column(
sa.Column("gateway_token", sqlmodel.sql.sqltypes.AutoString(), nullable=True)
)
if "gateway_main_session_key" not in columns:
batch.add_column(
sa.Column(
"gateway_main_session_key",
sqlmodel.sql.sqltypes.AutoString(),
nullable=True,
)
)
if "gateway_workspace_root" not in columns:
batch.add_column(
sa.Column(
"gateway_workspace_root",
sqlmodel.sql.sqltypes.AutoString(),
nullable=True,
)
)
if "gateways" in tables and "gateway_configs" not in tables:
op.rename_table("gateways", "gateway_configs")

View File

@@ -21,20 +21,29 @@ depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('boards',
op.create_table(
'gateway_configs',
sa.Column('id', sa.Uuid(), nullable=False),
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('gateway_url', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('gateway_token', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('gateway_main_session_key', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('gateway_workspace_root', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('identity_template', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('soul_template', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('url', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('token', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('main_session_key', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('workspace_root', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('boards',
sa.Column('id', sa.Uuid(), nullable=False),
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('gateway_config_id', sa.Uuid(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['gateway_config_id'], ['gateway_configs.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_boards_gateway_config_id'), 'boards', ['gateway_config_id'], unique=False)
op.create_index(op.f('ix_boards_slug'), 'boards', ['slug'], unique=False)
op.create_table('users',
sa.Column('id', sa.Uuid(), nullable=False),

View File

@@ -0,0 +1,104 @@
"""Add gateway skyll flag and agent templates.
Revision ID: c1c8b3b9f4d1
Revises: 939a1d2dc607
Create Date: 2026-02-04 22:18:00.000000
"""
from __future__ import annotations
import sqlalchemy as sa
import sqlmodel
from alembic import op
# revision identifiers, used by Alembic.
revision = "c1c8b3b9f4d1"
down_revision = "939a1d2dc607"
branch_labels = None
depends_on = None
def upgrade() -> None:
bind = op.get_bind()
inspector = sa.inspect(bind)
tables = set(inspector.get_table_names())
created_gateways = False
if "gateways" not in tables and "gateway_configs" not in tables:
op.create_table(
"gateways",
sa.Column("id", sa.Uuid(), nullable=False),
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column("url", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column("token", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column(
"main_session_key", sqlmodel.sql.sqltypes.AutoString(), nullable=False
),
sa.Column(
"workspace_root", sqlmodel.sql.sqltypes.AutoString(), nullable=False
),
sa.Column(
"skyll_enabled",
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.PrimaryKeyConstraint("id"),
)
tables.add("gateways")
created_gateways = True
if "gateways" in tables and not created_gateways:
existing_columns = {
column["name"] for column in inspector.get_columns("gateways")
}
if "skyll_enabled" in existing_columns:
pass
else:
op.add_column(
"gateways",
sa.Column(
"skyll_enabled",
sa.Boolean(),
nullable=False,
server_default=sa.false(),
),
)
op.alter_column("gateways", "skyll_enabled", server_default=None)
elif "gateways" in tables and created_gateways:
op.alter_column("gateways", "skyll_enabled", server_default=None)
elif "gateway_configs" in tables:
existing_columns = {
column["name"] for column in inspector.get_columns("gateway_configs")
}
if "skyll_enabled" in existing_columns:
pass
else:
op.add_column(
"gateway_configs",
sa.Column(
"skyll_enabled",
sa.Boolean(),
nullable=False,
server_default=sa.false(),
),
)
op.alter_column("gateway_configs", "skyll_enabled", server_default=None)
op.add_column(
"agents",
sa.Column("identity_template", sa.Text(), nullable=True),
)
op.add_column(
"agents",
sa.Column("soul_template", sa.Text(), nullable=True),
)
def downgrade() -> None:
op.drop_column("agents", "soul_template")
op.drop_column("agents", "identity_template")
bind = op.get_bind()
inspector = sa.inspect(bind)
tables = set(inspector.get_table_names())
if "gateways" in tables:
op.drop_column("gateways", "skyll_enabled")
elif "gateway_configs" in tables:
op.drop_column("gateway_configs", "skyll_enabled")