mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-10 08:05:22 +02:00
* feat: add deployment configuration options * Simplify EmbedDialog * Add options for inline vs floating embedding of agent
160 lines
5.6 KiB
Python
160 lines
5.6 KiB
Python
"""add embed token model
|
|
|
|
Revision ID: e02f387b7538
|
|
Revises: a57d25b75117
|
|
Create Date: 2025-11-11 12:49:35.515641
|
|
|
|
"""
|
|
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
from alembic_postgresql_enum import TableReference
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = "e02f387b7538"
|
|
down_revision: Union[str, None] = "a57d25b75117"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.create_table(
|
|
"embed_tokens",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("token", sa.String(length=255), nullable=False),
|
|
sa.Column("workflow_id", sa.Integer(), nullable=False),
|
|
sa.Column("organization_id", sa.Integer(), nullable=False),
|
|
sa.Column("allowed_domains", sa.JSON(), nullable=True),
|
|
sa.Column("settings", sa.JSON(), nullable=True),
|
|
sa.Column("is_active", sa.Boolean(), nullable=False),
|
|
sa.Column("usage_limit", sa.Integer(), nullable=True),
|
|
sa.Column("usage_count", sa.Integer(), nullable=False),
|
|
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("created_by", sa.Integer(), nullable=False),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(["created_by"], ["users.id"], ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(
|
|
["organization_id"], ["organizations.id"], ondelete="CASCADE"
|
|
),
|
|
sa.ForeignKeyConstraint(["workflow_id"], ["workflows.id"], ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(
|
|
op.f("ix_embed_tokens_is_active"), "embed_tokens", ["is_active"], unique=False
|
|
)
|
|
op.create_index(
|
|
op.f("ix_embed_tokens_organization_id"),
|
|
"embed_tokens",
|
|
["organization_id"],
|
|
unique=False,
|
|
)
|
|
op.create_index(
|
|
op.f("ix_embed_tokens_token"), "embed_tokens", ["token"], unique=True
|
|
)
|
|
op.create_index(
|
|
op.f("ix_embed_tokens_workflow_id"),
|
|
"embed_tokens",
|
|
["workflow_id"],
|
|
unique=False,
|
|
)
|
|
op.create_table(
|
|
"embed_sessions",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("session_token", sa.String(length=255), nullable=False),
|
|
sa.Column("embed_token_id", sa.Integer(), nullable=False),
|
|
sa.Column("workflow_run_id", sa.Integer(), nullable=True),
|
|
sa.Column("client_ip", sa.String(length=45), nullable=True),
|
|
sa.Column("user_agent", sa.String(length=500), nullable=True),
|
|
sa.Column("origin", sa.String(length=255), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.ForeignKeyConstraint(
|
|
["embed_token_id"], ["embed_tokens.id"], ondelete="CASCADE"
|
|
),
|
|
sa.ForeignKeyConstraint(
|
|
["workflow_run_id"], ["workflow_runs.id"], ondelete="CASCADE"
|
|
),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(
|
|
op.f("ix_embed_sessions_expires_at"),
|
|
"embed_sessions",
|
|
["expires_at"],
|
|
unique=False,
|
|
)
|
|
op.create_index(
|
|
op.f("ix_embed_sessions_session_token"),
|
|
"embed_sessions",
|
|
["session_token"],
|
|
unique=True,
|
|
)
|
|
op.alter_column(
|
|
"organizations",
|
|
"quota_reset_day",
|
|
existing_type=sa.INTEGER(),
|
|
server_default=sa.text("1"),
|
|
existing_nullable=False,
|
|
)
|
|
op.sync_enum_values(
|
|
enum_schema="public",
|
|
enum_name="workflow_run_mode",
|
|
new_values=[
|
|
"twilio",
|
|
"vonage",
|
|
"stasis",
|
|
"webrtc",
|
|
"smallwebrtc",
|
|
"VOICE",
|
|
"CHAT",
|
|
],
|
|
affected_columns=[
|
|
TableReference(
|
|
table_schema="public", table_name="workflow_runs", column_name="mode"
|
|
)
|
|
],
|
|
enum_values_to_rename=[],
|
|
)
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.sync_enum_values(
|
|
enum_schema="public",
|
|
enum_name="workflow_run_mode",
|
|
new_values=[
|
|
"twilio",
|
|
"stasis",
|
|
"webrtc",
|
|
"smallwebrtc",
|
|
"VOICE",
|
|
"CHAT",
|
|
"vonage",
|
|
],
|
|
affected_columns=[
|
|
TableReference(
|
|
table_schema="public", table_name="workflow_runs", column_name="mode"
|
|
)
|
|
],
|
|
enum_values_to_rename=[],
|
|
)
|
|
op.alter_column(
|
|
"organizations",
|
|
"quota_reset_day",
|
|
existing_type=sa.INTEGER(),
|
|
server_default=sa.text("LEAST((EXTRACT(day FROM CURRENT_DATE))::integer, 28)"),
|
|
existing_nullable=False,
|
|
)
|
|
op.drop_index(op.f("ix_embed_sessions_session_token"), table_name="embed_sessions")
|
|
op.drop_index(op.f("ix_embed_sessions_expires_at"), table_name="embed_sessions")
|
|
op.drop_table("embed_sessions")
|
|
op.drop_index(op.f("ix_embed_tokens_workflow_id"), table_name="embed_tokens")
|
|
op.drop_index(op.f("ix_embed_tokens_token"), table_name="embed_tokens")
|
|
op.drop_index(op.f("ix_embed_tokens_organization_id"), table_name="embed_tokens")
|
|
op.drop_index(op.f("ix_embed_tokens_is_active"), table_name="embed_tokens")
|
|
op.drop_table("embed_tokens")
|
|
# ### end Alembic commands ###
|