feat:mysql adaptation for meta db (#50)

* phase1:uuid stringdefault timestamp date

* phase2:json adapt

* phase3:BinaryData,ARRAY,Text,

* fix sa.String()

* fix defalut valud

* models adapt

* models adapt supplement

* fix pg unique dialect

* supplement

* migration fix

* migration fix

* date sql adapt

* model adapt fix

* config adapt

* migration fix

* fix

* fix anotation in .env.example

* config feat

* config fix

* .env.example adapt fix
This commit is contained in:
longbingljw 2025-11-07 15:35:31 +08:00 committed by GitHub
parent 829796514a
commit fcc71124b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
125 changed files with 6096 additions and 2427 deletions

1
.gitignore vendored
View File

@ -183,6 +183,7 @@ docker/volumes/couchbase/*
docker/volumes/oceanbase/* docker/volumes/oceanbase/*
docker/volumes/plugin_daemon/* docker/volumes/plugin_daemon/*
docker/volumes/matrixone/* docker/volumes/matrixone/*
docker/volumes/mysql/data/*
!docker/volumes/oceanbase/init.d !docker/volumes/oceanbase/init.d
docker/nginx/conf.d/default.conf docker/nginx/conf.d/default.conf

View File

@ -69,12 +69,31 @@ REDIS_CLUSTERS_PASSWORD=
# celery configuration # celery configuration
CELERY_BROKER_URL=redis://:difyai123456@localhost:${REDIS_PORT}/1 CELERY_BROKER_URL=redis://:difyai123456@localhost:${REDIS_PORT}/1
CELERY_BACKEND=redis CELERY_BACKEND=redis
# PostgreSQL database configuration
DB_USERNAME=postgres # Database configuration
DB_PASSWORD=difyai123456 DB_TYPE=postgresql
DB_HOST=localhost
DB_PORT=5432 # PostgreSQL configuration
DB_DATABASE=dify POSTGRES_USER=postgres
POSTGRES_PASSWORD=difyai123456
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DATABASE=dify
# MySQL configuration
MYSQL_USER=root
MYSQL_PASSWORD=difyai123456
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_DATABASE=dify
# OceanBase configuration
OCEANBASE_USER=root@test
OCEANBASE_PASSWORD=difyai123456
OCEANBASE_HOST=localhost
OCEANBASE_PORT=2881
OCEANBASE_DATABASE=test
SQLALCHEMY_POOL_PRE_PING=true SQLALCHEMY_POOL_PRE_PING=true
SQLALCHEMY_POOL_TIMEOUT=30 SQLALCHEMY_POOL_TIMEOUT=30
@ -172,6 +191,15 @@ WEAVIATE_API_KEY=WVF5YThaHlkYwhGUSmCRgsX3tD5ngdN8pkih
WEAVIATE_GRPC_ENABLED=false WEAVIATE_GRPC_ENABLED=false
WEAVIATE_BATCH_SIZE=100 WEAVIATE_BATCH_SIZE=100
# OceanBase Vector configuration
OCEANBASE_HOST=127.0.0.1
OCEANBASE_PORT=2881
OCEANBASE_USER=root@test
OCEANBASE_PASSWORD=difyai123456
OCEANBASE_DATABASE=test
OCEANBASE_MEMORY_LIMIT=6G
OCEANBASE_ENABLE_HYBRID_SEARCH=false
# Qdrant configuration, use `http://localhost:6333` for local mode or `https://your-qdrant-cluster-url.qdrant.io` for remote mode # Qdrant configuration, use `http://localhost:6333` for local mode or `https://your-qdrant-cluster-url.qdrant.io` for remote mode
QDRANT_URL=http://localhost:6333 QDRANT_URL=http://localhost:6333
QDRANT_API_KEY=difyai123456 QDRANT_API_KEY=difyai123456
@ -337,15 +365,6 @@ LINDORM_PASSWORD=admin
LINDORM_USING_UGC=True LINDORM_USING_UGC=True
LINDORM_QUERY_TIMEOUT=1 LINDORM_QUERY_TIMEOUT=1
# OceanBase Vector configuration
OCEANBASE_VECTOR_HOST=127.0.0.1
OCEANBASE_VECTOR_PORT=2881
OCEANBASE_VECTOR_USER=root@test
OCEANBASE_VECTOR_PASSWORD=difyai123456
OCEANBASE_VECTOR_DATABASE=test
OCEANBASE_MEMORY_LIMIT=6G
OCEANBASE_ENABLE_HYBRID_SEARCH=false
# AlibabaCloud MySQL Vector configuration # AlibabaCloud MySQL Vector configuration
ALIBABACLOUD_MYSQL_HOST=127.0.0.1 ALIBABACLOUD_MYSQL_HOST=127.0.0.1
ALIBABACLOUD_MYSQL_PORT=3306 ALIBABACLOUD_MYSQL_PORT=3306

View File

@ -15,8 +15,8 @@
```bash ```bash
cd ../docker cd ../docker
cp middleware.env.example middleware.env cp middleware.env.example middleware.env
# change the profile to other vector database if you are not using weaviate # change the profile to mysql if you are not using postgres,change the profile to other vector database if you are not using weaviate
docker compose -f docker-compose.middleware.yaml --profile weaviate -p dify up -d docker compose -f docker-compose.middleware.yaml --profile postgresql --profile weaviate -p dify up -d
cd ../api cd ../api
``` ```

View File

@ -105,31 +105,141 @@ class KeywordStoreConfig(BaseSettings):
class DatabaseConfig(BaseSettings): class DatabaseConfig(BaseSettings):
DB_HOST: str = Field( # Database type selector
description="Hostname or IP address of the database server.", DB_TYPE: Literal["postgresql", "mysql", "oceanbase"] = Field(
description="Database type to use. OceanBase is MySQL-compatible.",
default="postgresql",
)
# PostgreSQL configuration
POSTGRES_HOST: str = Field(
description="PostgreSQL hostname or IP address.",
default="localhost", default="localhost",
) )
DB_PORT: PositiveInt = Field( POSTGRES_PORT: PositiveInt = Field(
description="Port number for database connection.", description="PostgreSQL port number.",
default=5432, default=5432,
) )
DB_USERNAME: str = Field( POSTGRES_USER: str = Field(
description="Username for database authentication.", description="PostgreSQL username.",
default="postgres", default="postgres",
) )
DB_PASSWORD: str = Field( POSTGRES_PASSWORD: str = Field(
description="Password for database authentication.", description="PostgreSQL password.",
default="", default="difyai123456",
) )
DB_DATABASE: str = Field( POSTGRES_DATABASE: str = Field(
description="Name of the database to connect to.", description="PostgreSQL database name.",
default="dify", default="dify",
) )
# MySQL configuration
MYSQL_HOST: str = Field(
description="MySQL hostname or IP address.",
default="localhost",
)
MYSQL_PORT: PositiveInt = Field(
description="MySQL port number.",
default=3306,
)
MYSQL_USER: str = Field(
description="MySQL username.",
default="root",
)
MYSQL_PASSWORD: str = Field(
description="MySQL password.",
default="difyai123456",
)
MYSQL_DATABASE: str = Field(
description="MySQL database name.",
default="dify",
)
# OceanBase configuration (MySQL-compatible)
OCEANBASE_HOST: str = Field(
description="OceanBase hostname or IP address.",
default="localhost",
)
OCEANBASE_PORT: PositiveInt = Field(
description="OceanBase port number.",
default=2881,
)
OCEANBASE_USER: str = Field(
description="OceanBase username.",
default="root@test",
)
OCEANBASE_PASSWORD: str = Field(
description="OceanBase password.",
default="difyai123456",
)
OCEANBASE_DATABASE: str = Field(
description="OceanBase database name.",
default="test",
)
# Dynamic properties based on DB_TYPE
@computed_field # type: ignore[prop-decorator]
@property
def DB_HOST(self) -> str:
if self.DB_TYPE == "postgresql":
return self.POSTGRES_HOST
elif self.DB_TYPE == "oceanbase":
return self.OCEANBASE_HOST
else:
return self.MYSQL_HOST
@computed_field # type: ignore[prop-decorator]
@property
def DB_PORT(self) -> int:
if self.DB_TYPE == "postgresql":
return self.POSTGRES_PORT
elif self.DB_TYPE == "oceanbase":
return self.OCEANBASE_PORT
else:
return self.MYSQL_PORT
@computed_field # type: ignore[prop-decorator]
@property
def DB_USERNAME(self) -> str:
if self.DB_TYPE == "postgresql":
return self.POSTGRES_USER
elif self.DB_TYPE == "oceanbase":
return self.OCEANBASE_USER
else:
return self.MYSQL_USER
@computed_field # type: ignore[prop-decorator]
@property
def DB_PASSWORD(self) -> str:
if self.DB_TYPE == "postgresql":
return self.POSTGRES_PASSWORD
elif self.DB_TYPE == "oceanbase":
return self.OCEANBASE_PASSWORD
else:
return self.MYSQL_PASSWORD
@computed_field # type: ignore[prop-decorator]
@property
def DB_DATABASE(self) -> str:
if self.DB_TYPE == "postgresql":
return self.POSTGRES_DATABASE
elif self.DB_TYPE == "oceanbase":
return self.OCEANBASE_DATABASE
else:
return self.MYSQL_DATABASE
DB_CHARSET: str = Field( DB_CHARSET: str = Field(
description="Character set for database connection.", description="Character set for database connection.",
default="", default="",
@ -140,10 +250,10 @@ class DatabaseConfig(BaseSettings):
default="", default="",
) )
SQLALCHEMY_DATABASE_URI_SCHEME: str = Field( @computed_field # type: ignore[prop-decorator]
description="Database URI scheme for SQLAlchemy connection.", @property
default="postgresql", def SQLALCHEMY_DATABASE_URI_SCHEME(self) -> str:
) return "postgresql" if self.DB_TYPE == "postgresql" else "mysql+pymysql"
@computed_field # type: ignore[prop-decorator] @computed_field # type: ignore[prop-decorator]
@property @property
@ -204,15 +314,15 @@ class DatabaseConfig(BaseSettings):
# Parse DB_EXTRAS for 'options' # Parse DB_EXTRAS for 'options'
db_extras_dict = dict(parse_qsl(self.DB_EXTRAS)) db_extras_dict = dict(parse_qsl(self.DB_EXTRAS))
options = db_extras_dict.get("options", "") options = db_extras_dict.get("options", "")
# Always include timezone connect_args = {}
timezone_opt = "-c timezone=UTC" # Use the dynamic SQLALCHEMY_DATABASE_URI_SCHEME property
if options: if self.SQLALCHEMY_DATABASE_URI_SCHEME.startswith("postgresql"):
# Merge user options and timezone timezone_opt = "-c timezone=UTC"
merged_options = f"{options} {timezone_opt}" if options:
else: merged_options = f"{options} {timezone_opt}"
merged_options = timezone_opt else:
merged_options = timezone_opt
connect_args = {"options": merged_options} connect_args = {"options": merged_options}
return { return {
"pool_size": self.SQLALCHEMY_POOL_SIZE, "pool_size": self.SQLALCHEMY_POOL_SIZE,

View File

@ -7,27 +7,27 @@ class OceanBaseVectorConfig(BaseSettings):
Configuration settings for OceanBase Vector database Configuration settings for OceanBase Vector database
""" """
OCEANBASE_VECTOR_HOST: str | None = Field( OCEANBASE_HOST: str | None = Field(
description="Hostname or IP address of the OceanBase Vector server (e.g. 'localhost')", description="Hostname or IP address of the OceanBase Vector server (e.g. 'localhost')",
default=None, default=None,
) )
OCEANBASE_VECTOR_PORT: PositiveInt | None = Field( OCEANBASE_PORT: PositiveInt | None = Field(
description="Port number on which the OceanBase Vector server is listening (default is 2881)", description="Port number on which the OceanBase Vector server is listening (default is 2881)",
default=2881, default=2881,
) )
OCEANBASE_VECTOR_USER: str | None = Field( OCEANBASE_USER: str | None = Field(
description="Username for authenticating with the OceanBase Vector database", description="Username for authenticating with the OceanBase Vector database",
default=None, default=None,
) )
OCEANBASE_VECTOR_PASSWORD: str | None = Field( OCEANBASE_PASSWORD: str | None = Field(
description="Password for authenticating with the OceanBase Vector database", description="Password for authenticating with the OceanBase Vector database",
default=None, default=None,
) )
OCEANBASE_VECTOR_DATABASE: str | None = Field( OCEANBASE_DATABASE: str | None = Field(
description="Name of the OceanBase Vector database to connect to", description="Name of the OceanBase Vector database to connect to",
default=None, default=None,
) )

View File

@ -10,9 +10,9 @@ from controllers.console.wraps import account_initialization_required, setup_req
from core.app.entities.app_invoke_entities import InvokeFrom from core.app.entities.app_invoke_entities import InvokeFrom
from extensions.ext_database import db from extensions.ext_database import db
from libs.datetime_utils import parse_time_range from libs.datetime_utils import parse_time_range
from libs.helper import DatetimeString from libs.helper import DatetimeString, convert_datetime_to_date
from libs.login import current_account_with_tenant, login_required from libs.login import current_account_with_tenant, login_required
from models import AppMode, Message from models import AppMode
@console_ns.route("/apps/<uuid:app_id>/statistics/daily-messages") @console_ns.route("/apps/<uuid:app_id>/statistics/daily-messages")
@ -44,8 +44,9 @@ class DailyMessageStatistic(Resource):
) )
args = parser.parse_args() args = parser.parse_args()
sql_query = """SELECT converted_created_at = convert_datetime_to_date("created_at")
DATE(DATE_TRUNC('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE :tz )) AS date, sql_query = f"""SELECT
{converted_created_at} AS date,
COUNT(*) AS message_count COUNT(*) AS message_count
FROM FROM
messages messages
@ -108,6 +109,17 @@ class DailyConversationStatistic(Resource):
.add_argument("end", type=DatetimeString("%Y-%m-%d %H:%M"), location="args") .add_argument("end", type=DatetimeString("%Y-%m-%d %H:%M"), location="args")
) )
args = parser.parse_args() args = parser.parse_args()
converted_created_at = convert_datetime_to_date("created_at")
sql_query = f"""SELECT
{converted_created_at} AS date,
COUNT(DISTINCT conversation_id) AS conversation_count
FROM
messages
WHERE
app_id = :app_id
AND invoke_from != :invoke_from"""
arg_dict = {"tz": account.timezone, "app_id": app_model.id, "invoke_from": InvokeFrom.DEBUGGER}
assert account.timezone is not None assert account.timezone is not None
try: try:
@ -115,30 +127,21 @@ class DailyConversationStatistic(Resource):
except ValueError as e: except ValueError as e:
abort(400, description=str(e)) abort(400, description=str(e))
stmt = (
sa.select(
sa.func.date(
sa.func.date_trunc("day", sa.text("created_at AT TIME ZONE 'UTC' AT TIME ZONE :tz"))
).label("date"),
sa.func.count(sa.distinct(Message.conversation_id)).label("conversation_count"),
)
.select_from(Message)
.where(Message.app_id == app_model.id, Message.invoke_from != InvokeFrom.DEBUGGER)
)
if start_datetime_utc: if start_datetime_utc:
stmt = stmt.where(Message.created_at >= start_datetime_utc) sql_query += " AND created_at >= :start"
arg_dict["start"] = start_datetime_utc
if end_datetime_utc: if end_datetime_utc:
stmt = stmt.where(Message.created_at < end_datetime_utc) sql_query += " AND created_at < :end"
arg_dict["end"] = end_datetime_utc
stmt = stmt.group_by("date").order_by("date") sql_query += " GROUP BY date ORDER BY date"
response_data = [] response_data = []
with db.engine.begin() as conn: with db.engine.begin() as conn:
rs = conn.execute(stmt, {"tz": account.timezone}) rs = conn.execute(sa.text(sql_query), arg_dict)
for row in rs: for i in rs:
response_data.append({"date": str(row.date), "conversation_count": row.conversation_count}) response_data.append({"date": str(i.date), "conversation_count": i.conversation_count})
return jsonify({"data": response_data}) return jsonify({"data": response_data})
@ -172,8 +175,9 @@ class DailyTerminalsStatistic(Resource):
) )
args = parser.parse_args() args = parser.parse_args()
sql_query = """SELECT converted_created_at = convert_datetime_to_date("created_at")
DATE(DATE_TRUNC('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE :tz )) AS date, sql_query = f"""SELECT
{converted_created_at} AS date,
COUNT(DISTINCT messages.from_end_user_id) AS terminal_count COUNT(DISTINCT messages.from_end_user_id) AS terminal_count
FROM FROM
messages messages
@ -237,8 +241,9 @@ class DailyTokenCostStatistic(Resource):
) )
args = parser.parse_args() args = parser.parse_args()
sql_query = """SELECT converted_created_at = convert_datetime_to_date("created_at")
DATE(DATE_TRUNC('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE :tz )) AS date, sql_query = f"""SELECT
{converted_created_at} AS date,
(SUM(messages.message_tokens) + SUM(messages.answer_tokens)) AS token_count, (SUM(messages.message_tokens) + SUM(messages.answer_tokens)) AS token_count,
SUM(total_price) AS total_price SUM(total_price) AS total_price
FROM FROM
@ -305,8 +310,9 @@ class AverageSessionInteractionStatistic(Resource):
) )
args = parser.parse_args() args = parser.parse_args()
sql_query = """SELECT converted_created_at = convert_datetime_to_date("c.created_at")
DATE(DATE_TRUNC('day', c.created_at AT TIME ZONE 'UTC' AT TIME ZONE :tz )) AS date, sql_query = f"""SELECT
{converted_created_at} AS date,
AVG(subquery.message_count) AS interactions AVG(subquery.message_count) AS interactions
FROM FROM
( (
@ -389,8 +395,9 @@ class UserSatisfactionRateStatistic(Resource):
) )
args = parser.parse_args() args = parser.parse_args()
sql_query = """SELECT converted_created_at = convert_datetime_to_date("m.created_at")
DATE(DATE_TRUNC('day', m.created_at AT TIME ZONE 'UTC' AT TIME ZONE :tz )) AS date, sql_query = f"""SELECT
{converted_created_at} AS date,
COUNT(m.id) AS message_count, COUNT(m.id) AS message_count,
COUNT(mf.id) AS feedback_count COUNT(mf.id) AS feedback_count
FROM FROM
@ -463,8 +470,9 @@ class AverageResponseTimeStatistic(Resource):
) )
args = parser.parse_args() args = parser.parse_args()
sql_query = """SELECT converted_created_at = convert_datetime_to_date("created_at")
DATE(DATE_TRUNC('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE :tz )) AS date, sql_query = f"""SELECT
{converted_created_at} AS date,
AVG(provider_response_latency) AS latency AVG(provider_response_latency) AS latency
FROM FROM
messages messages
@ -528,8 +536,9 @@ class TokensPerSecondStatistic(Resource):
) )
args = parser.parse_args() args = parser.parse_args()
sql_query = """SELECT converted_created_at = convert_datetime_to_date("created_at")
DATE(DATE_TRUNC('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE :tz )) AS date, sql_query = f"""SELECT
{converted_created_at} AS date,
CASE CASE
WHEN SUM(provider_response_latency) = 0 THEN 0 WHEN SUM(provider_response_latency) = 0 THEN 0
ELSE (SUM(answer_tokens) / SUM(provider_response_latency)) ELSE (SUM(answer_tokens) / SUM(provider_response_latency))

View File

@ -37,13 +37,13 @@ class OceanBaseVectorConfig(BaseModel):
@classmethod @classmethod
def validate_config(cls, values: dict): def validate_config(cls, values: dict):
if not values["host"]: if not values["host"]:
raise ValueError("config OCEANBASE_VECTOR_HOST is required") raise ValueError("config OCEANBASE_HOST is required")
if not values["port"]: if not values["port"]:
raise ValueError("config OCEANBASE_VECTOR_PORT is required") raise ValueError("config OCEANBASE_PORT is required")
if not values["user"]: if not values["user"]:
raise ValueError("config OCEANBASE_VECTOR_USER is required") raise ValueError("config OCEANBASE_USER is required")
if not values["database"]: if not values["database"]:
raise ValueError("config OCEANBASE_VECTOR_DATABASE is required") raise ValueError("config OCEANBASE_DATABASE is required")
return values return values
@ -316,11 +316,11 @@ class OceanBaseVectorFactory(AbstractVectorFactory):
return OceanBaseVector( return OceanBaseVector(
collection_name, collection_name,
OceanBaseVectorConfig( OceanBaseVectorConfig(
host=dify_config.OCEANBASE_VECTOR_HOST or "", host=dify_config.OCEANBASE_HOST or "",
port=dify_config.OCEANBASE_VECTOR_PORT or 0, port=dify_config.OCEANBASE_PORT or 0,
user=dify_config.OCEANBASE_VECTOR_USER or "", user=dify_config.OCEANBASE_USER or "",
password=(dify_config.OCEANBASE_VECTOR_PASSWORD or ""), password=(dify_config.OCEANBASE_PASSWORD or ""),
database=dify_config.OCEANBASE_VECTOR_DATABASE or "", database=dify_config.OCEANBASE_DATABASE or "",
enable_hybrid_search=dify_config.OCEANBASE_ENABLE_HYBRID_SEARCH or False, enable_hybrid_search=dify_config.OCEANBASE_ENABLE_HYBRID_SEARCH or False,
), ),
) )

View File

@ -14,6 +14,7 @@ from sqlalchemy.orm import Session
from yarl import URL from yarl import URL
import contexts import contexts
from configs import dify_config
from core.helper.provider_cache import ToolProviderCredentialsCache from core.helper.provider_cache import ToolProviderCredentialsCache
from core.plugin.impl.tool import PluginToolManager from core.plugin.impl.tool import PluginToolManager
from core.tools.__base.tool_provider import ToolProviderController from core.tools.__base.tool_provider import ToolProviderController
@ -33,7 +34,6 @@ from services.tools.mcp_tools_manage_service import MCPToolManageService
if TYPE_CHECKING: if TYPE_CHECKING:
from core.workflow.nodes.tool.entities import ToolEntity from core.workflow.nodes.tool.entities import ToolEntity
from configs import dify_config
from core.agent.entities import AgentToolEntity from core.agent.entities import AgentToolEntity
from core.app.entities.app_invoke_entities import InvokeFrom from core.app.entities.app_invoke_entities import InvokeFrom
from core.helper.module_import_helper import load_single_subclass_from_source from core.helper.module_import_helper import load_single_subclass_from_source
@ -621,12 +621,28 @@ class ToolManager:
""" """
# according to multi credentials, select the one with is_default=True first, then created_at oldest # according to multi credentials, select the one with is_default=True first, then created_at oldest
# for compatibility with old version # for compatibility with old version
sql = """ if dify_config.SQLALCHEMY_DATABASE_URI_SCHEME == "postgresql":
# PostgreSQL: Use DISTINCT ON
sql = """
SELECT DISTINCT ON (tenant_id, provider) id SELECT DISTINCT ON (tenant_id, provider) id
FROM tool_builtin_providers FROM tool_builtin_providers
WHERE tenant_id = :tenant_id WHERE tenant_id = :tenant_id
ORDER BY tenant_id, provider, is_default DESC, created_at DESC ORDER BY tenant_id, provider, is_default DESC, created_at DESC
""" """
else:
# MySQL: Use window function to achieve same result
sql = """
SELECT id FROM (
SELECT id,
ROW_NUMBER() OVER (
PARTITION BY tenant_id, provider
ORDER BY is_default DESC, created_at DESC
) as rn
FROM tool_builtin_providers
WHERE tenant_id = :tenant_id
) ranked WHERE rn = 1
"""
with Session(db.engine, autoflush=False) as session: with Session(db.engine, autoflush=False) as session:
ids = [row.id for row in session.execute(sa.text(sql), {"tenant_id": tenant_id}).all()] ids = [row.id for row in session.execute(sa.text(sql), {"tenant_id": tenant_id}).all()]
return session.query(BuiltinToolProvider).where(BuiltinToolProvider.id.in_(ids)).all() return session.query(BuiltinToolProvider).where(BuiltinToolProvider.id.in_(ids)).all()

View File

@ -177,6 +177,15 @@ def timezone(timezone_string):
raise ValueError(error) raise ValueError(error)
def convert_datetime_to_date(field, target_timezone: str = ":tz"):
if dify_config.SQLALCHEMY_DATABASE_URI_SCHEME == "postgresql":
return f"DATE(DATE_TRUNC('day', {field} AT TIME ZONE 'UTC' AT TIME ZONE {target_timezone}))"
elif "mysql" in dify_config.SQLALCHEMY_DATABASE_URI_SCHEME:
return f"DATE(CONVERT_TZ({field}, 'UTC', {target_timezone}))"
else:
raise NotImplementedError(f"Unsupported database URI scheme: {dify_config.SQLALCHEMY_DATABASE_URI_SCHEME}")
def generate_string(n): def generate_string(n):
letters_digits = string.ascii_letters + string.digits letters_digits = string.ascii_letters + string.digits
result = "" result = ""

View File

@ -8,6 +8,12 @@ Create Date: 2024-01-07 04:07:34.482983
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '00bacef91f18' revision = '00bacef91f18'
down_revision = '8ec536f3c800' down_revision = '8ec536f3c800'
@ -17,17 +23,31 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('description', sa.Text(), nullable=False))
batch_op.drop_column('description_str') if _is_pg(conn):
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('description', sa.Text(), nullable=False))
batch_op.drop_column('description_str')
else:
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('description', models.types.LongText(), nullable=False))
batch_op.drop_column('description_str')
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('description_str', sa.TEXT(), autoincrement=False, nullable=False))
batch_op.drop_column('description') if _is_pg(conn):
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('description_str', sa.TEXT(), autoincrement=False, nullable=False))
batch_op.drop_column('description')
else:
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('description_str', models.types.LongText(), autoincrement=False, nullable=False))
batch_op.drop_column('description')
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,9 +7,14 @@ Create Date: 2024-06-12 07:49:07.666510
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
import models.types import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '04c602f5dc9b' revision = '04c602f5dc9b'
down_revision = '4ff534e1eb11' down_revision = '4ff534e1eb11'
@ -19,15 +24,28 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('tracing_app_configs', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False), if _is_pg(conn):
sa.Column('tracing_provider', sa.String(length=255), nullable=True), op.create_table('tracing_app_configs',
sa.Column('tracing_config', sa.JSON(), nullable=True), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.Column('tracing_provider', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('id', name='tracing_app_config_pkey') sa.Column('tracing_config', sa.JSON(), nullable=True),
) sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('id', name='tracing_app_config_pkey')
)
else:
op.create_table('tracing_app_configs',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('tracing_provider', sa.String(length=255), nullable=True),
sa.Column('tracing_config', sa.JSON(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.now(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.now(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tracing_app_config_pkey')
)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,8 +7,15 @@ Create Date: 2024-01-12 06:47:21.656262
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '053da0c1d756' revision = '053da0c1d756'
down_revision = '4829e54d2fee' down_revision = '4829e54d2fee'
@ -18,16 +25,31 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('tool_conversation_variables', conn = op.get_bind()
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('user_id', postgresql.UUID(), nullable=False), if _is_pg(conn):
sa.Column('tenant_id', postgresql.UUID(), nullable=False), op.create_table('tool_conversation_variables',
sa.Column('conversation_id', postgresql.UUID(), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('variables_str', sa.Text(), nullable=False), sa.Column('user_id', postgresql.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('conversation_id', postgresql.UUID(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_conversation_variables_pkey') sa.Column('variables_str', sa.Text(), nullable=False),
) sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_conversation_variables_pkey')
)
else:
op.create_table('tool_conversation_variables',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('user_id', models.types.StringUUID(), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('conversation_id', models.types.StringUUID(), nullable=False),
sa.Column('variables_str', models.types.LongText(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_conversation_variables_pkey')
)
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op: with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('privacy_policy', sa.String(length=255), nullable=True)) batch_op.add_column(sa.Column('privacy_policy', sa.String(length=255), nullable=True))
batch_op.alter_column('icon', batch_op.alter_column('icon',

View File

@ -9,6 +9,12 @@ import sqlalchemy as sa
from alembic import op from alembic import op
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '114eed84c228' revision = '114eed84c228'
down_revision = 'c71211c8f604' down_revision = 'c71211c8f604'
@ -26,7 +32,13 @@ def upgrade():
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tool_model_invokes', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('tool_id', postgresql.UUID(), autoincrement=False, nullable=False))
if _is_pg(conn):
with op.batch_alter_table('tool_model_invokes', schema=None) as batch_op:
batch_op.add_column(sa.Column('tool_id', postgresql.UUID(), autoincrement=False, nullable=False))
else:
with op.batch_alter_table('tool_model_invokes', schema=None) as batch_op:
batch_op.add_column(sa.Column('tool_id', models.types.StringUUID(), autoincrement=False, nullable=False))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,7 +8,11 @@ Create Date: 2024-07-05 14:30:59.472593
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
import models as models import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '161cadc1af8d' revision = '161cadc1af8d'
@ -19,9 +23,16 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('dataset_permissions', schema=None) as batch_op: conn = op.get_bind()
# Step 1: Add column without NOT NULL constraint
op.add_column('dataset_permissions', sa.Column('tenant_id', sa.UUID(), nullable=False)) if _is_pg(conn):
with op.batch_alter_table('dataset_permissions', schema=None) as batch_op:
# Step 1: Add column without NOT NULL constraint
op.add_column('dataset_permissions', sa.Column('tenant_id', sa.UUID(), nullable=False))
else:
with op.batch_alter_table('dataset_permissions', schema=None) as batch_op:
# Step 1: Add column without NOT NULL constraint
op.add_column('dataset_permissions', sa.Column('tenant_id', models.types.StringUUID(), nullable=False))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,8 +7,15 @@ Create Date: 2023-08-06 16:57:51.248337
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '16fa53d9faec' revision = '16fa53d9faec'
down_revision = '8d2d099ceb74' down_revision = '8d2d099ceb74'
@ -18,44 +25,87 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('provider_models', conn = op.get_bind()
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', postgresql.UUID(), nullable=False), if _is_pg(conn):
sa.Column('provider_name', sa.String(length=40), nullable=False), op.create_table('provider_models',
sa.Column('model_name', sa.String(length=40), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('model_type', sa.String(length=40), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=False),
sa.Column('encrypted_config', sa.Text(), nullable=True), sa.Column('provider_name', sa.String(length=40), nullable=False),
sa.Column('is_valid', sa.Boolean(), server_default=sa.text('false'), nullable=False), sa.Column('model_name', sa.String(length=40), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('model_type', sa.String(length=40), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('encrypted_config', sa.Text(), nullable=True),
sa.PrimaryKeyConstraint('id', name='provider_model_pkey'), sa.Column('is_valid', sa.Boolean(), server_default=sa.text('false'), nullable=False),
sa.UniqueConstraint('tenant_id', 'provider_name', 'model_name', 'model_type', name='unique_provider_model_name') sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
) sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='provider_model_pkey'),
sa.UniqueConstraint('tenant_id', 'provider_name', 'model_name', 'model_type', name='unique_provider_model_name')
)
else:
op.create_table('provider_models',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('provider_name', sa.String(length=40), nullable=False),
sa.Column('model_name', sa.String(length=40), nullable=False),
sa.Column('model_type', sa.String(length=40), nullable=False),
sa.Column('encrypted_config', models.types.LongText(), nullable=True),
sa.Column('is_valid', sa.Boolean(), server_default=sa.text('false'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='provider_model_pkey'),
sa.UniqueConstraint('tenant_id', 'provider_name', 'model_name', 'model_type', name='unique_provider_model_name')
)
with op.batch_alter_table('provider_models', schema=None) as batch_op: with op.batch_alter_table('provider_models', schema=None) as batch_op:
batch_op.create_index('provider_model_tenant_id_provider_idx', ['tenant_id', 'provider_name'], unique=False) batch_op.create_index('provider_model_tenant_id_provider_idx', ['tenant_id', 'provider_name'], unique=False)
op.create_table('tenant_default_models', if _is_pg(conn):
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False), op.create_table('tenant_default_models',
sa.Column('tenant_id', postgresql.UUID(), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('provider_name', sa.String(length=40), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=False),
sa.Column('model_name', sa.String(length=40), nullable=False), sa.Column('provider_name', sa.String(length=40), nullable=False),
sa.Column('model_type', sa.String(length=40), nullable=False), sa.Column('model_name', sa.String(length=40), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('model_type', sa.String(length=40), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='tenant_default_model_pkey') sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
) sa.PrimaryKeyConstraint('id', name='tenant_default_model_pkey')
)
else:
op.create_table('tenant_default_models',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('provider_name', sa.String(length=40), nullable=False),
sa.Column('model_name', sa.String(length=40), nullable=False),
sa.Column('model_type', sa.String(length=40), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tenant_default_model_pkey')
)
with op.batch_alter_table('tenant_default_models', schema=None) as batch_op: with op.batch_alter_table('tenant_default_models', schema=None) as batch_op:
batch_op.create_index('tenant_default_model_tenant_id_provider_type_idx', ['tenant_id', 'provider_name', 'model_type'], unique=False) batch_op.create_index('tenant_default_model_tenant_id_provider_type_idx', ['tenant_id', 'provider_name', 'model_type'], unique=False)
op.create_table('tenant_preferred_model_providers', if _is_pg(conn):
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False), op.create_table('tenant_preferred_model_providers',
sa.Column('tenant_id', postgresql.UUID(), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('provider_name', sa.String(length=40), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=False),
sa.Column('preferred_provider_type', sa.String(length=40), nullable=False), sa.Column('provider_name', sa.String(length=40), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('preferred_provider_type', sa.String(length=40), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='tenant_preferred_model_provider_pkey') sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
) sa.PrimaryKeyConstraint('id', name='tenant_preferred_model_provider_pkey')
)
else:
op.create_table('tenant_preferred_model_providers',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('provider_name', sa.String(length=40), nullable=False),
sa.Column('preferred_provider_type', sa.String(length=40), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tenant_preferred_model_provider_pkey')
)
with op.batch_alter_table('tenant_preferred_model_providers', schema=None) as batch_op: with op.batch_alter_table('tenant_preferred_model_providers', schema=None) as batch_op:
batch_op.create_index('tenant_preferred_model_provider_tenant_provider_idx', ['tenant_id', 'provider_name'], unique=False) batch_op.create_index('tenant_preferred_model_provider_tenant_provider_idx', ['tenant_id', 'provider_name'], unique=False)

View File

@ -8,6 +8,10 @@ Create Date: 2024-04-01 09:48:54.232201
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '17b5ab037c40' revision = '17b5ab037c40'
down_revision = 'a8f9b3c45e4a' down_revision = 'a8f9b3c45e4a'
@ -17,9 +21,14 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
with op.batch_alter_table('dataset_keyword_tables', schema=None) as batch_op:
batch_op.add_column(sa.Column('data_source_type', sa.String(length=255), server_default=sa.text("'database'::character varying"), nullable=False)) if _is_pg(conn):
with op.batch_alter_table('dataset_keyword_tables', schema=None) as batch_op:
batch_op.add_column(sa.Column('data_source_type', sa.String(length=255), server_default=sa.text("'database'::character varying"), nullable=False))
else:
with op.batch_alter_table('dataset_keyword_tables', schema=None) as batch_op:
batch_op.add_column(sa.Column('data_source_type', sa.String(length=255), server_default=sa.text("'database'"), nullable=False))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -10,6 +10,10 @@ from alembic import op
import models as models import models as models
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '63a83fcf12ba' revision = '63a83fcf12ba'
down_revision = '1787fbae959a' down_revision = '1787fbae959a'
@ -19,21 +23,39 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('workflow__conversation_variables', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), nullable=False),
sa.Column('conversation_id', models.types.StringUUID(), nullable=False), if _is_pg(conn):
sa.Column('app_id', models.types.StringUUID(), nullable=False), op.create_table('workflow__conversation_variables',
sa.Column('data', sa.Text(), nullable=False), sa.Column('id', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('conversation_id', models.types.StringUUID(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.PrimaryKeyConstraint('id', 'conversation_id', name=op.f('workflow__conversation_variables_pkey')) sa.Column('data', sa.Text(), nullable=False),
) sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.PrimaryKeyConstraint('id', 'conversation_id', name=op.f('workflow__conversation_variables_pkey'))
)
else:
op.create_table('workflow__conversation_variables',
sa.Column('id', models.types.StringUUID(), nullable=False),
sa.Column('conversation_id', models.types.StringUUID(), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('data', models.types.LongText(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', 'conversation_id', name=op.f('workflow__conversation_variables_pkey'))
)
with op.batch_alter_table('workflow__conversation_variables', schema=None) as batch_op: with op.batch_alter_table('workflow__conversation_variables', schema=None) as batch_op:
batch_op.create_index(batch_op.f('workflow__conversation_variables_app_id_idx'), ['app_id'], unique=False) batch_op.create_index(batch_op.f('workflow__conversation_variables_app_id_idx'), ['app_id'], unique=False)
batch_op.create_index(batch_op.f('workflow__conversation_variables_created_at_idx'), ['created_at'], unique=False) batch_op.create_index(batch_op.f('workflow__conversation_variables_created_at_idx'), ['created_at'], unique=False)
with op.batch_alter_table('workflows', schema=None) as batch_op: if _is_pg(conn):
batch_op.add_column(sa.Column('conversation_variables', sa.Text(), server_default='{}', nullable=False)) with op.batch_alter_table('workflows', schema=None) as batch_op:
batch_op.add_column(sa.Column('conversation_variables', sa.Text(), server_default='{}', nullable=False))
else:
with op.batch_alter_table('workflows', schema=None) as batch_op:
batch_op.add_column(sa.Column('conversation_variables', models.types.LongText(), default='{}', nullable=False))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,9 +7,14 @@ Create Date: 2024-08-15 09:56:59.012490
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
import models as models import models as models
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '0251a1c768cc' revision = '0251a1c768cc'
down_revision = 'bbadea11becb' down_revision = 'bbadea11becb'
@ -19,18 +24,35 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('tidb_auth_bindings', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=True), if _is_pg(conn):
sa.Column('cluster_id', sa.String(length=255), nullable=False), op.create_table('tidb_auth_bindings',
sa.Column('cluster_name', sa.String(length=255), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('active', sa.Boolean(), server_default=sa.text('false'), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=True),
sa.Column('status', sa.String(length=255), server_default=sa.text("'CREATING'::character varying"), nullable=False), sa.Column('cluster_id', sa.String(length=255), nullable=False),
sa.Column('account', sa.String(length=255), nullable=False), sa.Column('cluster_name', sa.String(length=255), nullable=False),
sa.Column('password', sa.String(length=255), nullable=False), sa.Column('active', sa.Boolean(), server_default=sa.text('false'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('status', sa.String(length=255), server_default=sa.text("'CREATING'::character varying"), nullable=False),
sa.PrimaryKeyConstraint('id', name='tidb_auth_bindings_pkey') sa.Column('account', sa.String(length=255), nullable=False),
) sa.Column('password', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='tidb_auth_bindings_pkey')
)
else:
op.create_table('tidb_auth_bindings',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=True),
sa.Column('cluster_id', sa.String(length=255), nullable=False),
sa.Column('cluster_name', sa.String(length=255), nullable=False),
sa.Column('active', sa.Boolean(), server_default=sa.text('false'), nullable=False),
sa.Column('status', sa.String(length=255), server_default=sa.text("'CREATING'"), nullable=False),
sa.Column('account', sa.String(length=255), nullable=False),
sa.Column('password', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tidb_auth_bindings_pkey')
)
with op.batch_alter_table('tidb_auth_bindings', schema=None) as batch_op: with op.batch_alter_table('tidb_auth_bindings', schema=None) as batch_op:
batch_op.create_index('tidb_auth_bindings_active_idx', ['active'], unique=False) batch_op.create_index('tidb_auth_bindings_active_idx', ['active'], unique=False)
batch_op.create_index('tidb_auth_bindings_status_idx', ['status'], unique=False) batch_op.create_index('tidb_auth_bindings_status_idx', ['status'], unique=False)

View File

@ -10,6 +10,10 @@ from alembic import op
import models as models import models as models
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'd57ba9ebb251' revision = 'd57ba9ebb251'
down_revision = '675b5321501b' down_revision = '675b5321501b'
@ -22,8 +26,14 @@ def upgrade():
with op.batch_alter_table('messages', schema=None) as batch_op: with op.batch_alter_table('messages', schema=None) as batch_op:
batch_op.add_column(sa.Column('parent_message_id', models.types.StringUUID(), nullable=True)) batch_op.add_column(sa.Column('parent_message_id', models.types.StringUUID(), nullable=True))
# Set parent_message_id for existing messages to uuid_nil() to distinguish them from new messages with actual parent IDs or NULLs # Set parent_message_id for existing messages to distinguish them from new messages with actual parent IDs or NULLs
op.execute('UPDATE messages SET parent_message_id = uuid_nil() WHERE parent_message_id IS NULL') conn = op.get_bind()
if _is_pg(conn):
# PostgreSQL: Use uuid_nil() function
op.execute('UPDATE messages SET parent_message_id = uuid_nil() WHERE parent_message_id IS NULL')
else:
# MySQL: Use a specific UUID value to represent nil
op.execute("UPDATE messages SET parent_message_id = '00000000-0000-0000-0000-000000000000' WHERE parent_message_id IS NULL")
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -6,7 +6,11 @@ Create Date: 2024-09-24 09:22:43.570120
""" """
from alembic import op from alembic import op
import models as models import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
@ -19,30 +23,58 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('dataset_retriever_resources', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('document_id',
existing_type=sa.UUID(), if _is_pg(conn):
nullable=True) with op.batch_alter_table('dataset_retriever_resources', schema=None) as batch_op:
batch_op.alter_column('data_source_type', batch_op.alter_column('document_id',
existing_type=sa.TEXT(), existing_type=sa.UUID(),
nullable=True) nullable=True)
batch_op.alter_column('segment_id', batch_op.alter_column('data_source_type',
existing_type=sa.UUID(), existing_type=sa.TEXT(),
nullable=True) nullable=True)
batch_op.alter_column('segment_id',
existing_type=sa.UUID(),
nullable=True)
else:
with op.batch_alter_table('dataset_retriever_resources', schema=None) as batch_op:
batch_op.alter_column('document_id',
existing_type=models.types.StringUUID(),
nullable=True)
batch_op.alter_column('data_source_type',
existing_type=models.types.LongText(),
nullable=True)
batch_op.alter_column('segment_id',
existing_type=models.types.StringUUID(),
nullable=True)
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('dataset_retriever_resources', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('segment_id',
existing_type=sa.UUID(), if _is_pg(conn):
nullable=False) with op.batch_alter_table('dataset_retriever_resources', schema=None) as batch_op:
batch_op.alter_column('data_source_type', batch_op.alter_column('segment_id',
existing_type=sa.TEXT(), existing_type=sa.UUID(),
nullable=False) nullable=False)
batch_op.alter_column('document_id', batch_op.alter_column('data_source_type',
existing_type=sa.UUID(), existing_type=sa.TEXT(),
nullable=False) nullable=False)
batch_op.alter_column('document_id',
existing_type=sa.UUID(),
nullable=False)
else:
with op.batch_alter_table('dataset_retriever_resources', schema=None) as batch_op:
batch_op.alter_column('segment_id',
existing_type=models.types.StringUUID(),
nullable=False)
batch_op.alter_column('data_source_type',
existing_type=models.types.LongText(),
nullable=False)
batch_op.alter_column('document_id',
existing_type=models.types.StringUUID(),
nullable=False)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -9,6 +9,11 @@ from alembic import op
import models as models import models as models
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
from uuid import uuid4
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '33f5fac87f29' revision = '33f5fac87f29'
@ -19,34 +24,66 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('external_knowledge_apis', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False), if _is_pg(conn):
sa.Column('description', sa.String(length=255), nullable=False), op.create_table('external_knowledge_apis',
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('settings', sa.Text(), nullable=True), sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False), sa.Column('description', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('updated_by', models.types.StringUUID(), nullable=True), sa.Column('settings', sa.Text(), nullable=True),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.PrimaryKeyConstraint('id', name='external_knowledge_apis_pkey') sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
) sa.Column('updated_by', models.types.StringUUID(), nullable=True),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='external_knowledge_apis_pkey')
)
else:
op.create_table('external_knowledge_apis',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('description', sa.String(length=255), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('settings', models.types.LongText(), nullable=True),
sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_by', models.types.StringUUID(), nullable=True),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='external_knowledge_apis_pkey')
)
with op.batch_alter_table('external_knowledge_apis', schema=None) as batch_op: with op.batch_alter_table('external_knowledge_apis', schema=None) as batch_op:
batch_op.create_index('external_knowledge_apis_name_idx', ['name'], unique=False) batch_op.create_index('external_knowledge_apis_name_idx', ['name'], unique=False)
batch_op.create_index('external_knowledge_apis_tenant_idx', ['tenant_id'], unique=False) batch_op.create_index('external_knowledge_apis_tenant_idx', ['tenant_id'], unique=False)
op.create_table('external_knowledge_bindings', if _is_pg(conn):
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False), op.create_table('external_knowledge_bindings',
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('external_knowledge_api_id', models.types.StringUUID(), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('dataset_id', models.types.StringUUID(), nullable=False), sa.Column('external_knowledge_api_id', models.types.StringUUID(), nullable=False),
sa.Column('external_knowledge_id', sa.Text(), nullable=False), sa.Column('dataset_id', models.types.StringUUID(), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False), sa.Column('external_knowledge_id', sa.Text(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('updated_by', models.types.StringUUID(), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('updated_by', models.types.StringUUID(), nullable=True),
sa.PrimaryKeyConstraint('id', name='external_knowledge_bindings_pkey') sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
) sa.PrimaryKeyConstraint('id', name='external_knowledge_bindings_pkey')
)
else:
op.create_table('external_knowledge_bindings',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('external_knowledge_api_id', models.types.StringUUID(), nullable=False),
sa.Column('dataset_id', models.types.StringUUID(), nullable=False),
sa.Column('external_knowledge_id', sa.String(length=512), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_by', models.types.StringUUID(), nullable=True),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='external_knowledge_bindings_pkey')
)
with op.batch_alter_table('external_knowledge_bindings', schema=None) as batch_op: with op.batch_alter_table('external_knowledge_bindings', schema=None) as batch_op:
batch_op.create_index('external_knowledge_bindings_dataset_idx', ['dataset_id'], unique=False) batch_op.create_index('external_knowledge_bindings_dataset_idx', ['dataset_id'], unique=False)
batch_op.create_index('external_knowledge_bindings_external_knowledge_api_idx', ['external_knowledge_api_id'], unique=False) batch_op.create_index('external_knowledge_bindings_external_knowledge_api_idx', ['external_knowledge_api_id'], unique=False)

View File

@ -16,6 +16,10 @@ branch_labels = None
depends_on = None depends_on = None
def _is_pg(conn):
return conn.dialect.name == "postgresql"
def upgrade(): def upgrade():
def _has_name_or_size_column() -> bool: def _has_name_or_size_column() -> bool:
# We cannot access the database in offline mode, so assume # We cannot access the database in offline mode, so assume
@ -46,14 +50,26 @@ def upgrade():
if _has_name_or_size_column(): if _has_name_or_size_column():
return return
with op.batch_alter_table("tool_files", schema=None) as batch_op: if _is_pg(conn):
batch_op.add_column(sa.Column("name", sa.String(), nullable=True)) # PostgreSQL: Keep original syntax
batch_op.add_column(sa.Column("size", sa.Integer(), nullable=True)) with op.batch_alter_table("tool_files", schema=None) as batch_op:
op.execute("UPDATE tool_files SET name = '' WHERE name IS NULL") batch_op.add_column(sa.Column("name", sa.String(), nullable=True))
op.execute("UPDATE tool_files SET size = -1 WHERE size IS NULL") batch_op.add_column(sa.Column("size", sa.Integer(), nullable=True))
with op.batch_alter_table("tool_files", schema=None) as batch_op: op.execute("UPDATE tool_files SET name = '' WHERE name IS NULL")
batch_op.alter_column("name", existing_type=sa.String(), nullable=False) op.execute("UPDATE tool_files SET size = -1 WHERE size IS NULL")
batch_op.alter_column("size", existing_type=sa.Integer(), nullable=False) with op.batch_alter_table("tool_files", schema=None) as batch_op:
batch_op.alter_column("name", existing_type=sa.String(), nullable=False)
batch_op.alter_column("size", existing_type=sa.Integer(), nullable=False)
else:
# MySQL: Use compatible syntax
with op.batch_alter_table("tool_files", schema=None) as batch_op:
batch_op.add_column(sa.Column("name", sa.String(length=255), nullable=True))
batch_op.add_column(sa.Column("size", sa.Integer(), nullable=True))
op.execute("UPDATE tool_files SET name = '' WHERE name IS NULL")
op.execute("UPDATE tool_files SET size = -1 WHERE size IS NULL")
with op.batch_alter_table("tool_files", schema=None) as batch_op:
batch_op.alter_column("name", existing_type=sa.String(length=255), nullable=False)
batch_op.alter_column("size", existing_type=sa.Integer(), nullable=False)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -9,6 +9,11 @@ from alembic import op
import models as models import models as models
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
from uuid import uuid4
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '43fa78bc3b7d' revision = '43fa78bc3b7d'
@ -19,13 +24,25 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('whitelists', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=True), if _is_pg(conn):
sa.Column('category', sa.String(length=255), nullable=False), op.create_table('whitelists',
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.PrimaryKeyConstraint('id', name='whitelists_pkey') sa.Column('tenant_id', models.types.StringUUID(), nullable=True),
) sa.Column('category', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='whitelists_pkey')
)
else:
op.create_table('whitelists',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=True),
sa.Column('category', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='whitelists_pkey')
)
with op.batch_alter_table('whitelists', schema=None) as batch_op: with op.batch_alter_table('whitelists', schema=None) as batch_op:
batch_op.create_index('whitelists_tenant_idx', ['tenant_id'], unique=False) batch_op.create_index('whitelists_tenant_idx', ['tenant_id'], unique=False)

View File

@ -9,6 +9,11 @@ from alembic import op
import models as models import models as models
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
from uuid import uuid4
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '08ec4f75af5e' revision = '08ec4f75af5e'
@ -19,14 +24,26 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('account_plugin_permissions', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), if _is_pg(conn):
sa.Column('install_permission', sa.String(length=16), server_default='everyone', nullable=False), op.create_table('account_plugin_permissions',
sa.Column('debug_permission', sa.String(length=16), server_default='noone', nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.PrimaryKeyConstraint('id', name='account_plugin_permission_pkey'), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.UniqueConstraint('tenant_id', name='unique_tenant_plugin') sa.Column('install_permission', sa.String(length=16), server_default='everyone', nullable=False),
) sa.Column('debug_permission', sa.String(length=16), server_default='noone', nullable=False),
sa.PrimaryKeyConstraint('id', name='account_plugin_permission_pkey'),
sa.UniqueConstraint('tenant_id', name='unique_tenant_plugin')
)
else:
op.create_table('account_plugin_permissions',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('install_permission', sa.String(length=16), server_default='everyone', nullable=False),
sa.Column('debug_permission', sa.String(length=16), server_default='noone', nullable=False),
sa.PrimaryKeyConstraint('id', name='account_plugin_permission_pkey'),
sa.UniqueConstraint('tenant_id', name='unique_tenant_plugin')
)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -10,6 +10,10 @@ import models as models
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'f4d7ce70a7ca' revision = 'f4d7ce70a7ca'
down_revision = '93ad8c19c40b' down_revision = '93ad8c19c40b'
@ -19,23 +23,43 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('upload_files', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('source_url',
existing_type=sa.VARCHAR(length=255), if _is_pg(conn):
type_=sa.TEXT(), with op.batch_alter_table('upload_files', schema=None) as batch_op:
existing_nullable=False, batch_op.alter_column('source_url',
existing_server_default=sa.text("''::character varying")) existing_type=sa.VARCHAR(length=255),
type_=sa.TEXT(),
existing_nullable=False,
existing_server_default=sa.text("''::character varying"))
else:
with op.batch_alter_table('upload_files', schema=None) as batch_op:
batch_op.alter_column('source_url',
existing_type=sa.VARCHAR(length=255),
type_=models.types.LongText(),
existing_nullable=False,
existing_default=sa.text("''"))
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('upload_files', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('source_url',
existing_type=sa.TEXT(), if _is_pg(conn):
type_=sa.VARCHAR(length=255), with op.batch_alter_table('upload_files', schema=None) as batch_op:
existing_nullable=False, batch_op.alter_column('source_url',
existing_server_default=sa.text("''::character varying")) existing_type=sa.TEXT(),
type_=sa.VARCHAR(length=255),
existing_nullable=False,
existing_server_default=sa.text("''::character varying"))
else:
with op.batch_alter_table('upload_files', schema=None) as batch_op:
batch_op.alter_column('source_url',
existing_type=models.types.LongText(),
type_=sa.VARCHAR(length=255),
existing_nullable=False,
existing_default=sa.text("''"))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,6 +7,9 @@ Create Date: 2024-11-01 06:22:27.981398
""" """
from alembic import op from alembic import op
import models as models import models as models
def _is_pg(conn):
return conn.dialect.name == "postgresql"
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
@ -19,49 +22,91 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
op.execute("UPDATE recommended_apps SET custom_disclaimer = '' WHERE custom_disclaimer IS NULL") op.execute("UPDATE recommended_apps SET custom_disclaimer = '' WHERE custom_disclaimer IS NULL")
op.execute("UPDATE sites SET custom_disclaimer = '' WHERE custom_disclaimer IS NULL") op.execute("UPDATE sites SET custom_disclaimer = '' WHERE custom_disclaimer IS NULL")
op.execute("UPDATE tool_api_providers SET custom_disclaimer = '' WHERE custom_disclaimer IS NULL") op.execute("UPDATE tool_api_providers SET custom_disclaimer = '' WHERE custom_disclaimer IS NULL")
with op.batch_alter_table('recommended_apps', schema=None) as batch_op: if _is_pg(conn):
batch_op.alter_column('custom_disclaimer', with op.batch_alter_table('recommended_apps', schema=None) as batch_op:
existing_type=sa.VARCHAR(length=255), batch_op.alter_column('custom_disclaimer',
type_=sa.TEXT(), existing_type=sa.VARCHAR(length=255),
nullable=False) type_=sa.TEXT(),
nullable=False)
with op.batch_alter_table('sites', schema=None) as batch_op: with op.batch_alter_table('sites', schema=None) as batch_op:
batch_op.alter_column('custom_disclaimer', batch_op.alter_column('custom_disclaimer',
existing_type=sa.VARCHAR(length=255), existing_type=sa.VARCHAR(length=255),
type_=sa.TEXT(), type_=sa.TEXT(),
nullable=False) nullable=False)
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op: with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
batch_op.alter_column('custom_disclaimer', batch_op.alter_column('custom_disclaimer',
existing_type=sa.VARCHAR(length=255), existing_type=sa.VARCHAR(length=255),
type_=sa.TEXT(), type_=sa.TEXT(),
nullable=False) nullable=False)
else:
with op.batch_alter_table('recommended_apps', schema=None) as batch_op:
batch_op.alter_column('custom_disclaimer',
existing_type=sa.VARCHAR(length=255),
type_=models.types.LongText(),
nullable=False)
with op.batch_alter_table('sites', schema=None) as batch_op:
batch_op.alter_column('custom_disclaimer',
existing_type=sa.VARCHAR(length=255),
type_=models.types.LongText(),
nullable=False)
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
batch_op.alter_column('custom_disclaimer',
existing_type=sa.VARCHAR(length=255),
type_=models.types.LongText(),
nullable=False)
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('custom_disclaimer',
existing_type=sa.TEXT(), if _is_pg(conn):
type_=sa.VARCHAR(length=255), with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
nullable=True) batch_op.alter_column('custom_disclaimer',
existing_type=sa.TEXT(),
type_=sa.VARCHAR(length=255),
nullable=True)
with op.batch_alter_table('sites', schema=None) as batch_op: with op.batch_alter_table('sites', schema=None) as batch_op:
batch_op.alter_column('custom_disclaimer', batch_op.alter_column('custom_disclaimer',
existing_type=sa.TEXT(), existing_type=sa.TEXT(),
type_=sa.VARCHAR(length=255), type_=sa.VARCHAR(length=255),
nullable=True) nullable=True)
with op.batch_alter_table('recommended_apps', schema=None) as batch_op: with op.batch_alter_table('recommended_apps', schema=None) as batch_op:
batch_op.alter_column('custom_disclaimer', batch_op.alter_column('custom_disclaimer',
existing_type=sa.TEXT(), existing_type=sa.TEXT(),
type_=sa.VARCHAR(length=255), type_=sa.VARCHAR(length=255),
nullable=True) nullable=True)
else:
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
batch_op.alter_column('custom_disclaimer',
existing_type=models.types.LongText(),
type_=sa.VARCHAR(length=255),
nullable=True)
with op.batch_alter_table('sites', schema=None) as batch_op:
batch_op.alter_column('custom_disclaimer',
existing_type=models.types.LongText(),
type_=sa.VARCHAR(length=255),
nullable=True)
with op.batch_alter_table('recommended_apps', schema=None) as batch_op:
batch_op.alter_column('custom_disclaimer',
existing_type=models.types.LongText(),
type_=sa.VARCHAR(length=255),
nullable=True)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -10,6 +10,10 @@ import models as models
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '09a8d1878d9b' revision = '09a8d1878d9b'
down_revision = 'd07474999927' down_revision = 'd07474999927'
@ -19,55 +23,103 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('conversations', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('inputs',
existing_type=postgresql.JSON(astext_type=sa.Text()), if _is_pg(conn):
nullable=False) with op.batch_alter_table('conversations', schema=None) as batch_op:
batch_op.alter_column('inputs',
existing_type=postgresql.JSON(astext_type=sa.Text()),
nullable=False)
with op.batch_alter_table('messages', schema=None) as batch_op: with op.batch_alter_table('messages', schema=None) as batch_op:
batch_op.alter_column('inputs', batch_op.alter_column('inputs',
existing_type=postgresql.JSON(astext_type=sa.Text()), existing_type=postgresql.JSON(astext_type=sa.Text()),
nullable=False) nullable=False)
else:
with op.batch_alter_table('conversations', schema=None) as batch_op:
batch_op.alter_column('inputs',
existing_type=sa.JSON(),
nullable=False)
with op.batch_alter_table('messages', schema=None) as batch_op:
batch_op.alter_column('inputs',
existing_type=sa.JSON(),
nullable=False)
op.execute("UPDATE workflows SET updated_at = created_at WHERE updated_at IS NULL") op.execute("UPDATE workflows SET updated_at = created_at WHERE updated_at IS NULL")
op.execute("UPDATE workflows SET graph = '' WHERE graph IS NULL") op.execute("UPDATE workflows SET graph = '' WHERE graph IS NULL")
op.execute("UPDATE workflows SET features = '' WHERE features IS NULL") op.execute("UPDATE workflows SET features = '' WHERE features IS NULL")
if _is_pg(conn):
with op.batch_alter_table('workflows', schema=None) as batch_op: with op.batch_alter_table('workflows', schema=None) as batch_op:
batch_op.alter_column('graph', batch_op.alter_column('graph',
existing_type=sa.TEXT(), existing_type=sa.TEXT(),
nullable=False) nullable=False)
batch_op.alter_column('features', batch_op.alter_column('features',
existing_type=sa.TEXT(), existing_type=sa.TEXT(),
nullable=False) nullable=False)
batch_op.alter_column('updated_at', batch_op.alter_column('updated_at',
existing_type=postgresql.TIMESTAMP(), existing_type=postgresql.TIMESTAMP(),
nullable=False) nullable=False)
else:
with op.batch_alter_table('workflows', schema=None) as batch_op:
batch_op.alter_column('graph',
existing_type=models.types.LongText(),
nullable=False)
batch_op.alter_column('features',
existing_type=models.types.LongText(),
nullable=False)
batch_op.alter_column('updated_at',
existing_type=sa.TIMESTAMP(),
nullable=False)
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('workflows', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('updated_at',
existing_type=postgresql.TIMESTAMP(), if _is_pg(conn):
nullable=True) with op.batch_alter_table('workflows', schema=None) as batch_op:
batch_op.alter_column('features', batch_op.alter_column('updated_at',
existing_type=sa.TEXT(), existing_type=postgresql.TIMESTAMP(),
nullable=True) nullable=True)
batch_op.alter_column('graph', batch_op.alter_column('features',
existing_type=sa.TEXT(), existing_type=sa.TEXT(),
nullable=True) nullable=True)
batch_op.alter_column('graph',
existing_type=sa.TEXT(),
nullable=True)
else:
with op.batch_alter_table('workflows', schema=None) as batch_op:
batch_op.alter_column('updated_at',
existing_type=sa.TIMESTAMP(),
nullable=True)
batch_op.alter_column('features',
existing_type=models.types.LongText(),
nullable=True)
batch_op.alter_column('graph',
existing_type=models.types.LongText(),
nullable=True)
with op.batch_alter_table('messages', schema=None) as batch_op: if _is_pg(conn):
batch_op.alter_column('inputs', with op.batch_alter_table('messages', schema=None) as batch_op:
existing_type=postgresql.JSON(astext_type=sa.Text()), batch_op.alter_column('inputs',
nullable=True) existing_type=postgresql.JSON(astext_type=sa.Text()),
nullable=True)
with op.batch_alter_table('conversations', schema=None) as batch_op: with op.batch_alter_table('conversations', schema=None) as batch_op:
batch_op.alter_column('inputs', batch_op.alter_column('inputs',
existing_type=postgresql.JSON(astext_type=sa.Text()), existing_type=postgresql.JSON(astext_type=sa.Text()),
nullable=True) nullable=True)
else:
with op.batch_alter_table('messages', schema=None) as batch_op:
batch_op.alter_column('inputs',
existing_type=sa.JSON(),
nullable=True)
with op.batch_alter_table('conversations', schema=None) as batch_op:
batch_op.alter_column('inputs',
existing_type=sa.JSON(),
nullable=True)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,6 +8,11 @@ Create Date: 2024-11-22 07:01:17.550037
from alembic import op from alembic import op
import models as models import models as models
import sqlalchemy as sa import sqlalchemy as sa
from uuid import uuid4
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
@ -19,27 +24,53 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('child_chunks', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), if _is_pg(conn):
sa.Column('dataset_id', models.types.StringUUID(), nullable=False), op.create_table('child_chunks',
sa.Column('document_id', models.types.StringUUID(), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('segment_id', models.types.StringUUID(), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('position', sa.Integer(), nullable=False), sa.Column('dataset_id', models.types.StringUUID(), nullable=False),
sa.Column('content', sa.Text(), nullable=False), sa.Column('document_id', models.types.StringUUID(), nullable=False),
sa.Column('word_count', sa.Integer(), nullable=False), sa.Column('segment_id', models.types.StringUUID(), nullable=False),
sa.Column('index_node_id', sa.String(length=255), nullable=True), sa.Column('position', sa.Integer(), nullable=False),
sa.Column('index_node_hash', sa.String(length=255), nullable=True), sa.Column('content', sa.Text(), nullable=False),
sa.Column('type', sa.String(length=255), server_default=sa.text("'automatic'::character varying"), nullable=False), sa.Column('word_count', sa.Integer(), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False), sa.Column('index_node_id', sa.String(length=255), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('index_node_hash', sa.String(length=255), nullable=True),
sa.Column('updated_by', models.types.StringUUID(), nullable=True), sa.Column('type', sa.String(length=255), server_default=sa.text("'automatic'::character varying"), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('indexing_at', sa.DateTime(), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('completed_at', sa.DateTime(), nullable=True), sa.Column('updated_by', models.types.StringUUID(), nullable=True),
sa.Column('error', sa.Text(), nullable=True), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='child_chunk_pkey') sa.Column('indexing_at', sa.DateTime(), nullable=True),
) sa.Column('completed_at', sa.DateTime(), nullable=True),
sa.Column('error', sa.Text(), nullable=True),
sa.PrimaryKeyConstraint('id', name='child_chunk_pkey')
)
else:
op.create_table('child_chunks',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('dataset_id', models.types.StringUUID(), nullable=False),
sa.Column('document_id', models.types.StringUUID(), nullable=False),
sa.Column('segment_id', models.types.StringUUID(), nullable=False),
sa.Column('position', sa.Integer(), nullable=False),
sa.Column('content', models.types.LongText(), nullable=False),
sa.Column('word_count', sa.Integer(), nullable=False),
sa.Column('index_node_id', sa.String(length=255), nullable=True),
sa.Column('index_node_hash', sa.String(length=255), nullable=True),
sa.Column('type', sa.String(length=255), server_default=sa.text("'automatic'"), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_by', models.types.StringUUID(), nullable=True),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('indexing_at', sa.DateTime(), nullable=True),
sa.Column('completed_at', sa.DateTime(), nullable=True),
sa.Column('error', models.types.LongText(), nullable=True),
sa.PrimaryKeyConstraint('id', name='child_chunk_pkey')
)
with op.batch_alter_table('child_chunks', schema=None) as batch_op: with op.batch_alter_table('child_chunks', schema=None) as batch_op:
batch_op.create_index('child_chunk_dataset_id_idx', ['tenant_id', 'dataset_id', 'document_id', 'segment_id', 'index_node_id'], unique=False) batch_op.create_index('child_chunk_dataset_id_idx', ['tenant_id', 'dataset_id', 'document_id', 'segment_id', 'index_node_id'], unique=False)

View File

@ -9,6 +9,11 @@ from alembic import op
import models as models import models as models
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
from uuid import uuid4
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '11b07f66c737' revision = '11b07f66c737'
@ -25,15 +30,30 @@ def upgrade():
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('tool_providers', conn = op.get_bind()
sa.Column('id', sa.UUID(), server_default=sa.text('uuid_generate_v4()'), autoincrement=False, nullable=False),
sa.Column('tenant_id', sa.UUID(), autoincrement=False, nullable=False), if _is_pg(conn):
sa.Column('tool_name', sa.VARCHAR(length=40), autoincrement=False, nullable=False), op.create_table('tool_providers',
sa.Column('encrypted_credentials', sa.TEXT(), autoincrement=False, nullable=True), sa.Column('id', sa.UUID(), server_default=sa.text('uuid_generate_v4()'), autoincrement=False, nullable=False),
sa.Column('is_enabled', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False), sa.Column('tenant_id', sa.UUID(), autoincrement=False, nullable=False),
sa.Column('created_at', postgresql.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), autoincrement=False, nullable=False), sa.Column('tool_name', sa.VARCHAR(length=40), autoincrement=False, nullable=False),
sa.Column('updated_at', postgresql.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), autoincrement=False, nullable=False), sa.Column('encrypted_credentials', sa.TEXT(), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint('id', name='tool_provider_pkey'), sa.Column('is_enabled', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False),
sa.UniqueConstraint('tenant_id', 'tool_name', name='unique_tool_provider_tool_name') sa.Column('created_at', postgresql.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), autoincrement=False, nullable=False),
) sa.Column('updated_at', postgresql.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_provider_pkey'),
sa.UniqueConstraint('tenant_id', 'tool_name', name='unique_tool_provider_tool_name')
)
else:
op.create_table('tool_providers',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), autoincrement=False, nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), autoincrement=False, nullable=False),
sa.Column('tool_name', sa.VARCHAR(length=40), autoincrement=False, nullable=False),
sa.Column('encrypted_credentials', models.types.LongText(), autoincrement=False, nullable=True),
sa.Column('is_enabled', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.func.current_timestamp(), autoincrement=False, nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(), server_default=sa.func.current_timestamp(), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_provider_pkey'),
sa.UniqueConstraint('tenant_id', 'tool_name', name='unique_tool_provider_tool_name')
)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -9,6 +9,11 @@ from alembic import op
import models as models import models as models
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
from uuid import uuid4
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '923752d42eb6' revision = '923752d42eb6'
@ -19,15 +24,29 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('dataset_auto_disable_logs', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), if _is_pg(conn):
sa.Column('dataset_id', models.types.StringUUID(), nullable=False), op.create_table('dataset_auto_disable_logs',
sa.Column('document_id', models.types.StringUUID(), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('notified', sa.Boolean(), server_default=sa.text('false'), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('dataset_id', models.types.StringUUID(), nullable=False),
sa.PrimaryKeyConstraint('id', name='dataset_auto_disable_log_pkey') sa.Column('document_id', models.types.StringUUID(), nullable=False),
) sa.Column('notified', sa.Boolean(), server_default=sa.text('false'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='dataset_auto_disable_log_pkey')
)
else:
op.create_table('dataset_auto_disable_logs',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('dataset_id', models.types.StringUUID(), nullable=False),
sa.Column('document_id', models.types.StringUUID(), nullable=False),
sa.Column('notified', sa.Boolean(), server_default=sa.text('false'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='dataset_auto_disable_log_pkey')
)
with op.batch_alter_table('dataset_auto_disable_logs', schema=None) as batch_op: with op.batch_alter_table('dataset_auto_disable_logs', schema=None) as batch_op:
batch_op.create_index('dataset_auto_disable_log_created_atx', ['created_at'], unique=False) batch_op.create_index('dataset_auto_disable_log_created_atx', ['created_at'], unique=False)
batch_op.create_index('dataset_auto_disable_log_dataset_idx', ['dataset_id'], unique=False) batch_op.create_index('dataset_auto_disable_log_dataset_idx', ['dataset_id'], unique=False)

View File

@ -9,6 +9,11 @@ from alembic import op
import models as models import models as models
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
from uuid import uuid4
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'f051706725cc' revision = 'f051706725cc'
@ -19,14 +24,27 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('rate_limit_logs', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), if _is_pg(conn):
sa.Column('subscription_plan', sa.String(length=255), nullable=False), op.create_table('rate_limit_logs',
sa.Column('operation', sa.String(length=255), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.PrimaryKeyConstraint('id', name='rate_limit_log_pkey') sa.Column('subscription_plan', sa.String(length=255), nullable=False),
) sa.Column('operation', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='rate_limit_log_pkey')
)
else:
op.create_table('rate_limit_logs',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('subscription_plan', sa.String(length=255), nullable=False),
sa.Column('operation', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='rate_limit_log_pkey')
)
with op.batch_alter_table('rate_limit_logs', schema=None) as batch_op: with op.batch_alter_table('rate_limit_logs', schema=None) as batch_op:
batch_op.create_index('rate_limit_log_operation_idx', ['operation'], unique=False) batch_op.create_index('rate_limit_log_operation_idx', ['operation'], unique=False)
batch_op.create_index('rate_limit_log_tenant_idx', ['tenant_id'], unique=False) batch_op.create_index('rate_limit_log_tenant_idx', ['tenant_id'], unique=False)

View File

@ -9,6 +9,11 @@ from alembic import op
import models as models import models as models
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
from uuid import uuid4
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'd20049ed0af6' revision = 'd20049ed0af6'
@ -19,34 +24,68 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('dataset_metadata_bindings', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), if _is_pg(conn):
sa.Column('dataset_id', models.types.StringUUID(), nullable=False), # PostgreSQL: Keep original syntax
sa.Column('metadata_id', models.types.StringUUID(), nullable=False), op.create_table('dataset_metadata_bindings',
sa.Column('document_id', models.types.StringUUID(), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False), sa.Column('dataset_id', models.types.StringUUID(), nullable=False),
sa.PrimaryKeyConstraint('id', name='dataset_metadata_binding_pkey') sa.Column('metadata_id', models.types.StringUUID(), nullable=False),
) sa.Column('document_id', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.PrimaryKeyConstraint('id', name='dataset_metadata_binding_pkey')
)
else:
# MySQL: Use compatible syntax
op.create_table('dataset_metadata_bindings',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('dataset_id', models.types.StringUUID(), nullable=False),
sa.Column('metadata_id', models.types.StringUUID(), nullable=False),
sa.Column('document_id', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.PrimaryKeyConstraint('id', name='dataset_metadata_binding_pkey')
)
with op.batch_alter_table('dataset_metadata_bindings', schema=None) as batch_op: with op.batch_alter_table('dataset_metadata_bindings', schema=None) as batch_op:
batch_op.create_index('dataset_metadata_binding_dataset_idx', ['dataset_id'], unique=False) batch_op.create_index('dataset_metadata_binding_dataset_idx', ['dataset_id'], unique=False)
batch_op.create_index('dataset_metadata_binding_document_idx', ['document_id'], unique=False) batch_op.create_index('dataset_metadata_binding_document_idx', ['document_id'], unique=False)
batch_op.create_index('dataset_metadata_binding_metadata_idx', ['metadata_id'], unique=False) batch_op.create_index('dataset_metadata_binding_metadata_idx', ['metadata_id'], unique=False)
batch_op.create_index('dataset_metadata_binding_tenant_idx', ['tenant_id'], unique=False) batch_op.create_index('dataset_metadata_binding_tenant_idx', ['tenant_id'], unique=False)
op.create_table('dataset_metadatas', if _is_pg(conn):
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False), # PostgreSQL: Keep original syntax
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), op.create_table('dataset_metadatas',
sa.Column('dataset_id', models.types.StringUUID(), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('type', sa.String(length=255), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False), sa.Column('dataset_id', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('type', sa.String(length=255), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('updated_by', models.types.StringUUID(), nullable=True), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='dataset_metadata_pkey') sa.Column('created_by', models.types.StringUUID(), nullable=False),
) sa.Column('updated_by', models.types.StringUUID(), nullable=True),
sa.PrimaryKeyConstraint('id', name='dataset_metadata_pkey')
)
else:
# MySQL: Use compatible syntax
op.create_table('dataset_metadatas',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('dataset_id', models.types.StringUUID(), nullable=False),
sa.Column('type', sa.String(length=255), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('updated_by', models.types.StringUUID(), nullable=True),
sa.PrimaryKeyConstraint('id', name='dataset_metadata_pkey')
)
with op.batch_alter_table('dataset_metadatas', schema=None) as batch_op: with op.batch_alter_table('dataset_metadatas', schema=None) as batch_op:
batch_op.create_index('dataset_metadata_dataset_idx', ['dataset_id'], unique=False) batch_op.create_index('dataset_metadata_dataset_idx', ['dataset_id'], unique=False)
batch_op.create_index('dataset_metadata_tenant_idx', ['tenant_id'], unique=False) batch_op.create_index('dataset_metadata_tenant_idx', ['tenant_id'], unique=False)
@ -54,23 +93,31 @@ def upgrade():
with op.batch_alter_table('datasets', schema=None) as batch_op: with op.batch_alter_table('datasets', schema=None) as batch_op:
batch_op.add_column(sa.Column('built_in_field_enabled', sa.Boolean(), server_default=sa.text('false'), nullable=False)) batch_op.add_column(sa.Column('built_in_field_enabled', sa.Boolean(), server_default=sa.text('false'), nullable=False))
with op.batch_alter_table('documents', schema=None) as batch_op: if _is_pg(conn):
batch_op.alter_column('doc_metadata', with op.batch_alter_table('documents', schema=None) as batch_op:
existing_type=postgresql.JSON(astext_type=sa.Text()), batch_op.alter_column('doc_metadata',
type_=postgresql.JSONB(astext_type=sa.Text()), existing_type=postgresql.JSON(astext_type=sa.Text()),
existing_nullable=True) type_=postgresql.JSONB(astext_type=sa.Text()),
batch_op.create_index('document_metadata_idx', ['doc_metadata'], unique=False, postgresql_using='gin') existing_nullable=True)
batch_op.create_index('document_metadata_idx', ['doc_metadata'], unique=False, postgresql_using='gin')
else:
pass
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('documents', schema=None) as batch_op: conn = op.get_bind()
batch_op.drop_index('document_metadata_idx', postgresql_using='gin')
batch_op.alter_column('doc_metadata', if _is_pg(conn):
existing_type=postgresql.JSONB(astext_type=sa.Text()), with op.batch_alter_table('documents', schema=None) as batch_op:
type_=postgresql.JSON(astext_type=sa.Text()), batch_op.drop_index('document_metadata_idx', postgresql_using='gin')
existing_nullable=True) batch_op.alter_column('doc_metadata',
existing_type=postgresql.JSONB(astext_type=sa.Text()),
type_=postgresql.JSON(astext_type=sa.Text()),
existing_nullable=True)
else:
pass
with op.batch_alter_table('datasets', schema=None) as batch_op: with op.batch_alter_table('datasets', schema=None) as batch_op:
batch_op.drop_column('built_in_field_enabled') batch_op.drop_column('built_in_field_enabled')

View File

@ -17,10 +17,23 @@ branch_labels = None
depends_on = None depends_on = None
def _is_pg(conn):
return conn.dialect.name == "postgresql"
def upgrade(): def upgrade():
with op.batch_alter_table('workflows', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('marked_name', sa.String(), nullable=False, server_default=''))
batch_op.add_column(sa.Column('marked_comment', sa.String(), nullable=False, server_default='')) if _is_pg(conn):
# PostgreSQL: Keep original syntax
with op.batch_alter_table('workflows', schema=None) as batch_op:
batch_op.add_column(sa.Column('marked_name', sa.String(), nullable=False, server_default=''))
batch_op.add_column(sa.Column('marked_comment', sa.String(), nullable=False, server_default=''))
else:
# MySQL: Use compatible syntax
with op.batch_alter_table('workflows', schema=None) as batch_op:
batch_op.add_column(sa.Column('marked_name', sa.String(length=255), nullable=False, server_default=''))
batch_op.add_column(sa.Column('marked_comment', sa.String(length=255), nullable=False, server_default=''))
def downgrade(): def downgrade():

View File

@ -8,9 +8,14 @@ Create Date: 2025-05-15 15:31:03.128680
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
import models as models import models as models
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = "2adcbe1f5dfb" revision = "2adcbe1f5dfb"
down_revision = "d28f2004b072" down_revision = "d28f2004b072"
@ -20,24 +25,46 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table( conn = op.get_bind()
"workflow_draft_variables",
sa.Column("id", models.types.StringUUID(), server_default=sa.text("uuid_generate_v4()"), nullable=False), if _is_pg(conn):
sa.Column("created_at", sa.DateTime(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False), op.create_table(
sa.Column("updated_at", sa.DateTime(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False), "workflow_draft_variables",
sa.Column("app_id", models.types.StringUUID(), nullable=False), sa.Column("id", models.types.StringUUID(), server_default=sa.text("uuid_generate_v4()"), nullable=False),
sa.Column("last_edited_at", sa.DateTime(), nullable=True), sa.Column("created_at", sa.DateTime(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False),
sa.Column("node_id", sa.String(length=255), nullable=False), sa.Column("updated_at", sa.DateTime(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False),
sa.Column("name", sa.String(length=255), nullable=False), sa.Column("app_id", models.types.StringUUID(), nullable=False),
sa.Column("description", sa.String(length=255), nullable=False), sa.Column("last_edited_at", sa.DateTime(), nullable=True),
sa.Column("selector", sa.String(length=255), nullable=False), sa.Column("node_id", sa.String(length=255), nullable=False),
sa.Column("value_type", sa.String(length=20), nullable=False), sa.Column("name", sa.String(length=255), nullable=False),
sa.Column("value", sa.Text(), nullable=False), sa.Column("description", sa.String(length=255), nullable=False),
sa.Column("visible", sa.Boolean(), nullable=False), sa.Column("selector", sa.String(length=255), nullable=False),
sa.Column("editable", sa.Boolean(), nullable=False), sa.Column("value_type", sa.String(length=20), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("workflow_draft_variables_pkey")), sa.Column("value", sa.Text(), nullable=False),
sa.UniqueConstraint("app_id", "node_id", "name", name=op.f("workflow_draft_variables_app_id_key")), sa.Column("visible", sa.Boolean(), nullable=False),
) sa.Column("editable", sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("workflow_draft_variables_pkey")),
sa.UniqueConstraint("app_id", "node_id", "name", name=op.f("workflow_draft_variables_app_id_key")),
)
else:
op.create_table(
"workflow_draft_variables",
sa.Column("id", models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column("created_at", sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column("updated_at", sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column("app_id", models.types.StringUUID(), nullable=False),
sa.Column("last_edited_at", sa.DateTime(), nullable=True),
sa.Column("node_id", sa.String(length=255), nullable=False),
sa.Column("name", sa.String(length=255), nullable=False),
sa.Column("description", sa.String(length=255), nullable=False),
sa.Column("selector", sa.String(length=255), nullable=False),
sa.Column("value_type", sa.String(length=20), nullable=False),
sa.Column("value", models.types.LongText(), nullable=False),
sa.Column("visible", sa.Boolean(), nullable=False),
sa.Column("editable", sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("workflow_draft_variables_pkey")),
sa.UniqueConstraint("app_id", "node_id", "name", name=op.f("workflow_draft_variables_app_id_key")),
)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,6 +7,10 @@ Create Date: 2025-06-06 14:24:44.213018
""" """
from alembic import op from alembic import op
import models as models import models as models
def _is_pg(conn):
return conn.dialect.name == "postgresql"
import sqlalchemy as sa import sqlalchemy as sa
@ -18,19 +22,30 @@ depends_on = None
def upgrade(): def upgrade():
# `CREATE INDEX CONCURRENTLY` cannot run within a transaction, so use the `autocommit_block` # ### commands auto generated by Alembic - please adjust! ###
# context manager to wrap the index creation statement. conn = op.get_bind()
# Reference:
# if _is_pg(conn):
# - https://www.postgresql.org/docs/current/sql-createindex.html#:~:text=Another%20difference%20is,CREATE%20INDEX%20CONCURRENTLY%20cannot. # `CREATE INDEX CONCURRENTLY` cannot run within a transaction, so use the `autocommit_block`
# - https://alembic.sqlalchemy.org/en/latest/api/runtime.html#alembic.runtime.migration.MigrationContext.autocommit_block # context manager to wrap the index creation statement.
with op.get_context().autocommit_block(): # Reference:
#
# - https://www.postgresql.org/docs/current/sql-createindex.html#:~:text=Another%20difference%20is,CREATE%20INDEX%20CONCURRENTLY%20cannot.
# - https://alembic.sqlalchemy.org/en/latest/api/runtime.html#alembic.runtime.migration.MigrationContext.autocommit_block
with op.get_context().autocommit_block():
op.create_index(
op.f('workflow_node_executions_tenant_id_idx'),
"workflow_node_executions",
['tenant_id', 'workflow_id', 'node_id', sa.literal_column('created_at DESC')],
unique=False,
postgresql_concurrently=True,
)
else:
op.create_index( op.create_index(
op.f('workflow_node_executions_tenant_id_idx'), op.f('workflow_node_executions_tenant_id_idx'),
"workflow_node_executions", "workflow_node_executions",
['tenant_id', 'workflow_id', 'node_id', sa.literal_column('created_at DESC')], ['tenant_id', 'workflow_id', 'node_id', sa.literal_column('created_at DESC')],
unique=False, unique=False,
postgresql_concurrently=True,
) )
with op.batch_alter_table('workflow_draft_variables', schema=None) as batch_op: with op.batch_alter_table('workflow_draft_variables', schema=None) as batch_op:
@ -51,8 +66,13 @@ def downgrade():
# Reference: # Reference:
# #
# https://www.postgresql.org/docs/current/sql-createindex.html#:~:text=Another%20difference%20is,CREATE%20INDEX%20CONCURRENTLY%20cannot. # https://www.postgresql.org/docs/current/sql-createindex.html#:~:text=Another%20difference%20is,CREATE%20INDEX%20CONCURRENTLY%20cannot.
with op.get_context().autocommit_block(): conn = op.get_bind()
op.drop_index(op.f('workflow_node_executions_tenant_id_idx'), postgresql_concurrently=True)
if _is_pg(conn):
with op.get_context().autocommit_block():
op.drop_index(op.f('workflow_node_executions_tenant_id_idx'), postgresql_concurrently=True)
else:
op.drop_index(op.f('workflow_node_executions_tenant_id_idx'))
with op.batch_alter_table('workflow_draft_variables', schema=None) as batch_op: with op.batch_alter_table('workflow_draft_variables', schema=None) as batch_op:
batch_op.drop_column('node_execution_id') batch_op.drop_column('node_execution_id')

View File

@ -8,6 +8,11 @@ Create Date: 2025-06-25 09:36:07.510570
from alembic import op from alembic import op
import models as models import models as models
import sqlalchemy as sa import sqlalchemy as sa
from uuid import uuid4
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
@ -19,40 +24,80 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('app_mcp_servers', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), if _is_pg(conn):
sa.Column('app_id', models.types.StringUUID(), nullable=False), op.create_table('app_mcp_servers',
sa.Column('name', sa.String(length=255), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('description', sa.String(length=255), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('server_code', sa.String(length=255), nullable=False), sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('status', sa.String(length=255), server_default=sa.text("'normal'::character varying"), nullable=False), sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('parameters', sa.Text(), nullable=False), sa.Column('description', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('server_code', sa.String(length=255), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('status', sa.String(length=255), server_default=sa.text("'normal'::character varying"), nullable=False),
sa.PrimaryKeyConstraint('id', name='app_mcp_server_pkey'), sa.Column('parameters', sa.Text(), nullable=False),
sa.UniqueConstraint('tenant_id', 'app_id', name='unique_app_mcp_server_tenant_app_id'), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.UniqueConstraint('server_code', name='unique_app_mcp_server_server_code') sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
) sa.PrimaryKeyConstraint('id', name='app_mcp_server_pkey'),
op.create_table('tool_mcp_providers', sa.UniqueConstraint('tenant_id', 'app_id', name='unique_app_mcp_server_tenant_app_id'),
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False), sa.UniqueConstraint('server_code', name='unique_app_mcp_server_server_code')
sa.Column('name', sa.String(length=40), nullable=False), )
sa.Column('server_identifier', sa.String(length=24), nullable=False), else:
sa.Column('server_url', sa.Text(), nullable=False), op.create_table('app_mcp_servers',
sa.Column('server_url_hash', sa.String(length=64), nullable=False), sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('icon', sa.String(length=255), nullable=True), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('user_id', models.types.StringUUID(), nullable=False), sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('encrypted_credentials', sa.Text(), nullable=True), sa.Column('description', sa.String(length=255), nullable=False),
sa.Column('authed', sa.Boolean(), nullable=False), sa.Column('server_code', sa.String(length=255), nullable=False),
sa.Column('tools', sa.Text(), nullable=False), sa.Column('status', sa.String(length=255), server_default=sa.text("'normal'"), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('parameters', models.types.LongText(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_mcp_provider_pkey'), sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.UniqueConstraint('tenant_id', 'name', name='unique_mcp_provider_name'), sa.PrimaryKeyConstraint('id', name='app_mcp_server_pkey'),
sa.UniqueConstraint('tenant_id', 'server_identifier', name='unique_mcp_provider_server_identifier'), sa.UniqueConstraint('tenant_id', 'app_id', name='unique_app_mcp_server_tenant_app_id'),
sa.UniqueConstraint('tenant_id', 'server_url_hash', name='unique_mcp_provider_server_url') sa.UniqueConstraint('server_code', name='unique_app_mcp_server_server_code')
) )
if _is_pg(conn):
op.create_table('tool_mcp_providers',
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('name', sa.String(length=40), nullable=False),
sa.Column('server_identifier', sa.String(length=24), nullable=False),
sa.Column('server_url', sa.Text(), nullable=False),
sa.Column('server_url_hash', sa.String(length=64), nullable=False),
sa.Column('icon', sa.String(length=255), nullable=True),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('user_id', models.types.StringUUID(), nullable=False),
sa.Column('encrypted_credentials', sa.Text(), nullable=True),
sa.Column('authed', sa.Boolean(), nullable=False),
sa.Column('tools', sa.Text(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_mcp_provider_pkey'),
sa.UniqueConstraint('tenant_id', 'name', name='unique_mcp_provider_name'),
sa.UniqueConstraint('tenant_id', 'server_identifier', name='unique_mcp_provider_server_identifier'),
sa.UniqueConstraint('tenant_id', 'server_url_hash', name='unique_mcp_provider_server_url')
)
else:
op.create_table('tool_mcp_providers',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('name', sa.String(length=40), nullable=False),
sa.Column('server_identifier', sa.String(length=24), nullable=False),
sa.Column('server_url', models.types.LongText(), nullable=False),
sa.Column('server_url_hash', sa.String(length=64), nullable=False),
sa.Column('icon', sa.String(length=255), nullable=True),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('user_id', models.types.StringUUID(), nullable=False),
sa.Column('encrypted_credentials', models.types.LongText(), nullable=True),
sa.Column('authed', sa.Boolean(), nullable=False),
sa.Column('tools', models.types.LongText(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_mcp_provider_pkey'),
sa.UniqueConstraint('tenant_id', 'name', name='unique_mcp_provider_name'),
sa.UniqueConstraint('tenant_id', 'server_identifier', name='unique_mcp_provider_server_identifier'),
sa.UniqueConstraint('tenant_id', 'server_url_hash', name='unique_mcp_provider_server_url')
)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -27,6 +27,10 @@ import models as models
import sqlalchemy as sa import sqlalchemy as sa
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '1c9ba48be8e4' revision = '1c9ba48be8e4'
down_revision = '58eb7bdb93fe' down_revision = '58eb7bdb93fe'
@ -40,7 +44,11 @@ def upgrade():
# The ability to specify source timestamp has been removed because its type signature is incompatible with # The ability to specify source timestamp has been removed because its type signature is incompatible with
# PostgreSQL 18's `uuidv7` function. This capability is rarely needed in practice, as IDs can be # PostgreSQL 18's `uuidv7` function. This capability is rarely needed in practice, as IDs can be
# generated and controlled within the application layer. # generated and controlled within the application layer.
op.execute(sa.text(r""" conn = op.get_bind()
if _is_pg(conn):
# PostgreSQL: Create uuidv7 functions
op.execute(sa.text(r"""
/* Main function to generate a uuidv7 value with millisecond precision */ /* Main function to generate a uuidv7 value with millisecond precision */
CREATE FUNCTION uuidv7() RETURNS uuid CREATE FUNCTION uuidv7() RETURNS uuid
AS AS
@ -63,7 +71,7 @@ COMMENT ON FUNCTION uuidv7 IS
'Generate a uuid-v7 value with a 48-bit timestamp (millisecond precision) and 74 bits of randomness'; 'Generate a uuid-v7 value with a 48-bit timestamp (millisecond precision) and 74 bits of randomness';
""")) """))
op.execute(sa.text(r""" op.execute(sa.text(r"""
CREATE FUNCTION uuidv7_boundary(timestamptz) RETURNS uuid CREATE FUNCTION uuidv7_boundary(timestamptz) RETURNS uuid
AS AS
$$ $$
@ -79,8 +87,15 @@ COMMENT ON FUNCTION uuidv7_boundary(timestamptz) IS
'Generate a non-random uuidv7 with the given timestamp (first 48 bits) and all random bits to 0. As the smallest possible uuidv7 for that timestamp, it may be used as a boundary for partitions.'; 'Generate a non-random uuidv7 with the given timestamp (first 48 bits) and all random bits to 0. As the smallest possible uuidv7 for that timestamp, it may be used as a boundary for partitions.';
""" """
)) ))
else:
pass
def downgrade(): def downgrade():
op.execute(sa.text("DROP FUNCTION uuidv7")) conn = op.get_bind()
op.execute(sa.text("DROP FUNCTION uuidv7_boundary"))
if _is_pg(conn):
op.execute(sa.text("DROP FUNCTION uuidv7"))
op.execute(sa.text("DROP FUNCTION uuidv7_boundary"))
else:
pass

View File

@ -8,6 +8,11 @@ Create Date: 2025-06-24 17:05:43.118647
from alembic import op from alembic import op
import models as models import models as models
import sqlalchemy as sa import sqlalchemy as sa
from uuid import uuid4
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
@ -19,31 +24,63 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('tool_oauth_system_clients', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('plugin_id', sa.String(length=512), nullable=False), if _is_pg(conn):
sa.Column('provider', sa.String(length=255), nullable=False), op.create_table('tool_oauth_system_clients',
sa.Column('encrypted_oauth_params', sa.Text(), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_oauth_system_client_pkey'), sa.Column('plugin_id', sa.String(length=512), nullable=False),
sa.UniqueConstraint('plugin_id', 'provider', name='tool_oauth_system_client_plugin_id_provider_idx') sa.Column('provider', sa.String(length=255), nullable=False),
) sa.Column('encrypted_oauth_params', sa.Text(), nullable=False),
op.create_table('tool_oauth_tenant_clients', sa.PrimaryKeyConstraint('id', name='tool_oauth_system_client_pkey'),
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False), sa.UniqueConstraint('plugin_id', 'provider', name='tool_oauth_system_client_plugin_id_provider_idx')
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), )
sa.Column('plugin_id', sa.String(length=512), nullable=False), else:
sa.Column('provider', sa.String(length=255), nullable=False), op.create_table('tool_oauth_system_clients',
sa.Column('enabled', sa.Boolean(), server_default=sa.text('true'), nullable=False), sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('encrypted_oauth_params', sa.Text(), nullable=False), sa.Column('plugin_id', sa.String(length=512), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_oauth_tenant_client_pkey'), sa.Column('provider', sa.String(length=255), nullable=False),
sa.UniqueConstraint('tenant_id', 'plugin_id', 'provider', name='unique_tool_oauth_tenant_client') sa.Column('encrypted_oauth_params', models.types.LongText(), nullable=False),
) sa.PrimaryKeyConstraint('id', name='tool_oauth_system_client_pkey'),
sa.UniqueConstraint('plugin_id', 'provider', name='tool_oauth_system_client_plugin_id_provider_idx')
)
if _is_pg(conn):
op.create_table('tool_oauth_tenant_clients',
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('plugin_id', sa.String(length=512), nullable=False),
sa.Column('provider', sa.String(length=255), nullable=False),
sa.Column('enabled', sa.Boolean(), server_default=sa.text('true'), nullable=False),
sa.Column('encrypted_oauth_params', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_oauth_tenant_client_pkey'),
sa.UniqueConstraint('tenant_id', 'plugin_id', 'provider', name='unique_tool_oauth_tenant_client')
)
else:
op.create_table('tool_oauth_tenant_clients',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('plugin_id', sa.String(length=255), nullable=False),
sa.Column('provider', sa.String(length=255), nullable=False),
sa.Column('enabled', sa.Boolean(), server_default=sa.text('true'), nullable=False),
sa.Column('encrypted_oauth_params', models.types.LongText(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_oauth_tenant_client_pkey'),
sa.UniqueConstraint('tenant_id', 'plugin_id', 'provider', name='unique_tool_oauth_tenant_client')
)
with op.batch_alter_table('tool_builtin_providers', schema=None) as batch_op: if _is_pg(conn):
batch_op.add_column(sa.Column('name', sa.String(length=256), server_default=sa.text("'API KEY 1'::character varying"), nullable=False)) with op.batch_alter_table('tool_builtin_providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('is_default', sa.Boolean(), server_default=sa.text('false'), nullable=False)) batch_op.add_column(sa.Column('name', sa.String(length=256), server_default=sa.text("'API KEY 1'::character varying"), nullable=False))
batch_op.add_column(sa.Column('credential_type', sa.String(length=32), server_default=sa.text("'api-key'::character varying"), nullable=False)) batch_op.add_column(sa.Column('is_default', sa.Boolean(), server_default=sa.text('false'), nullable=False))
batch_op.drop_constraint(batch_op.f('unique_builtin_tool_provider'), type_='unique') batch_op.add_column(sa.Column('credential_type', sa.String(length=32), server_default=sa.text("'api-key'::character varying"), nullable=False))
batch_op.create_unique_constraint(batch_op.f('unique_builtin_tool_provider'), ['tenant_id', 'provider', 'name']) batch_op.drop_constraint(batch_op.f('unique_builtin_tool_provider'), type_='unique')
batch_op.create_unique_constraint(batch_op.f('unique_builtin_tool_provider'), ['tenant_id', 'provider', 'name'])
else:
with op.batch_alter_table('tool_builtin_providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('name', sa.String(length=256), server_default=sa.text("'API KEY 1'"), nullable=False))
batch_op.add_column(sa.Column('is_default', sa.Boolean(), server_default=sa.text('false'), nullable=False))
batch_op.add_column(sa.Column('credential_type', sa.String(length=32), server_default=sa.text("'api-key'"), nullable=False))
batch_op.drop_constraint(batch_op.f('unique_builtin_tool_provider'), type_='unique')
batch_op.create_unique_constraint(batch_op.f('unique_builtin_tool_provider'), ['tenant_id', 'provider', 'name'])
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -9,6 +9,11 @@ from alembic import op
import models as models import models as models
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
from uuid import uuid4
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '8bcc02c9bd07' revision = '8bcc02c9bd07'
@ -19,19 +24,36 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('tenant_plugin_auto_upgrade_strategies', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), if _is_pg(conn):
sa.Column('strategy_setting', sa.String(length=16), server_default='fix_only', nullable=False), op.create_table('tenant_plugin_auto_upgrade_strategies',
sa.Column('upgrade_time_of_day', sa.Integer(), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('upgrade_mode', sa.String(length=16), server_default='exclude', nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('exclude_plugins', sa.ARRAY(sa.String(length=255)), nullable=False), sa.Column('strategy_setting', sa.String(length=16), server_default='fix_only', nullable=False),
sa.Column('include_plugins', sa.ARRAY(sa.String(length=255)), nullable=False), sa.Column('upgrade_time_of_day', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('upgrade_mode', sa.String(length=16), server_default='exclude', nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('exclude_plugins', sa.ARRAY(sa.String(length=255)), nullable=False),
sa.PrimaryKeyConstraint('id', name='tenant_plugin_auto_upgrade_strategy_pkey'), sa.Column('include_plugins', sa.ARRAY(sa.String(length=255)), nullable=False),
sa.UniqueConstraint('tenant_id', name='unique_tenant_plugin_auto_upgrade_strategy') sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
) sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.PrimaryKeyConstraint('id', name='tenant_plugin_auto_upgrade_strategy_pkey'),
sa.UniqueConstraint('tenant_id', name='unique_tenant_plugin_auto_upgrade_strategy')
)
else:
op.create_table('tenant_plugin_auto_upgrade_strategies',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('strategy_setting', sa.String(length=16), server_default='fix_only', nullable=False),
sa.Column('upgrade_time_of_day', sa.Integer(), nullable=False),
sa.Column('upgrade_mode', sa.String(length=16), server_default='exclude', nullable=False),
sa.Column('exclude_plugins', sa.JSON(), nullable=False),
sa.Column('include_plugins', sa.JSON(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tenant_plugin_auto_upgrade_strategy_pkey'),
sa.UniqueConstraint('tenant_id', name='unique_tenant_plugin_auto_upgrade_strategy')
)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,6 +7,10 @@ Create Date: 2025-07-24 14:50:48.779833
""" """
from alembic import op from alembic import op
import models as models import models as models
def _is_pg(conn):
return conn.dialect.name == "postgresql"
import sqlalchemy as sa import sqlalchemy as sa
@ -18,8 +22,18 @@ depends_on = None
def upgrade(): def upgrade():
op.execute("ALTER TABLE tidb_auth_bindings ALTER COLUMN status SET DEFAULT 'CREATING'::character varying") conn = op.get_bind()
if _is_pg(conn):
op.execute("ALTER TABLE tidb_auth_bindings ALTER COLUMN status SET DEFAULT 'CREATING'::character varying")
else:
op.execute("ALTER TABLE tidb_auth_bindings ALTER COLUMN status SET DEFAULT 'CREATING'")
def downgrade(): def downgrade():
op.execute("ALTER TABLE tidb_auth_bindings ALTER COLUMN status SET DEFAULT 'CREATING'") conn = op.get_bind()
if _is_pg(conn):
op.execute("ALTER TABLE tidb_auth_bindings ALTER COLUMN status SET DEFAULT 'CREATING'::character varying")
else:
op.execute("ALTER TABLE tidb_auth_bindings ALTER COLUMN status SET DEFAULT 'CREATING'")

View File

@ -11,6 +11,10 @@ import models as models
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.sql import table, column from sqlalchemy.sql import table, column
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'e8446f481c1e' revision = 'e8446f481c1e'
down_revision = 'fa8b0fa6f407' down_revision = 'fa8b0fa6f407'
@ -20,16 +24,30 @@ depends_on = None
def upgrade(): def upgrade():
# Create provider_credentials table # Create provider_credentials table
op.create_table('provider_credentials', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), if _is_pg(conn):
sa.Column('provider_name', sa.String(length=255), nullable=False), op.create_table('provider_credentials',
sa.Column('credential_name', sa.String(length=255), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.Column('encrypted_config', sa.Text(), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('provider_name', sa.String(length=255), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('credential_name', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id', name='provider_credential_pkey') sa.Column('encrypted_config', sa.Text(), nullable=False),
) sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.PrimaryKeyConstraint('id', name='provider_credential_pkey')
)
else:
op.create_table('provider_credentials',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuidv7()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('provider_name', sa.String(length=255), nullable=False),
sa.Column('credential_name', sa.String(length=255), nullable=False),
sa.Column('encrypted_config', models.types.LongText(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='provider_credential_pkey')
)
# Create index for provider_credentials # Create index for provider_credentials
with op.batch_alter_table('provider_credentials', schema=None) as batch_op: with op.batch_alter_table('provider_credentials', schema=None) as batch_op:
@ -60,27 +78,49 @@ def upgrade():
def migrate_existing_providers_data(): def migrate_existing_providers_data():
"""migrate providers table data to provider_credentials""" """migrate providers table data to provider_credentials"""
conn = op.get_bind()
# Define table structure for data manipulation # Define table structure for data manipulation
providers_table = table('providers', if _is_pg(conn):
column('id', models.types.StringUUID()), providers_table = table('providers',
column('tenant_id', models.types.StringUUID()), column('id', models.types.StringUUID()),
column('provider_name', sa.String()), column('tenant_id', models.types.StringUUID()),
column('encrypted_config', sa.Text()), column('provider_name', sa.String()),
column('created_at', sa.DateTime()), column('encrypted_config', sa.Text()),
column('updated_at', sa.DateTime()), column('created_at', sa.DateTime()),
column('credential_id', models.types.StringUUID()), column('updated_at', sa.DateTime()),
) column('credential_id', models.types.StringUUID()),
)
else:
providers_table = table('providers',
column('id', models.types.StringUUID()),
column('tenant_id', models.types.StringUUID()),
column('provider_name', sa.String()),
column('encrypted_config', models.types.LongText()),
column('created_at', sa.DateTime()),
column('updated_at', sa.DateTime()),
column('credential_id', models.types.StringUUID()),
)
provider_credential_table = table('provider_credentials', if _is_pg(conn):
column('id', models.types.StringUUID()), provider_credential_table = table('provider_credentials',
column('tenant_id', models.types.StringUUID()), column('id', models.types.StringUUID()),
column('provider_name', sa.String()), column('tenant_id', models.types.StringUUID()),
column('credential_name', sa.String()), column('provider_name', sa.String()),
column('encrypted_config', sa.Text()), column('credential_name', sa.String()),
column('created_at', sa.DateTime()), column('encrypted_config', sa.Text()),
column('updated_at', sa.DateTime()) column('created_at', sa.DateTime()),
) column('updated_at', sa.DateTime())
)
else:
provider_credential_table = table('provider_credentials',
column('id', models.types.StringUUID()),
column('tenant_id', models.types.StringUUID()),
column('provider_name', sa.String()),
column('credential_name', sa.String()),
column('encrypted_config', models.types.LongText()),
column('created_at', sa.DateTime()),
column('updated_at', sa.DateTime())
)
# Get database connection # Get database connection
conn = op.get_bind() conn = op.get_bind()
@ -123,8 +163,14 @@ def migrate_existing_providers_data():
def downgrade(): def downgrade():
# Re-add encrypted_config column to providers table # Re-add encrypted_config column to providers table
with op.batch_alter_table('providers', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('encrypted_config', sa.Text(), nullable=True))
if _is_pg(conn):
with op.batch_alter_table('providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('encrypted_config', sa.Text(), nullable=True))
else:
with op.batch_alter_table('providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('encrypted_config', models.types.LongText(), nullable=True))
# Migrate data back from provider_credentials to providers # Migrate data back from provider_credentials to providers

View File

@ -13,6 +13,10 @@ import sqlalchemy as sa
from sqlalchemy.sql import table, column from sqlalchemy.sql import table, column
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '0e154742a5fa' revision = '0e154742a5fa'
down_revision = 'e8446f481c1e' down_revision = 'e8446f481c1e'
@ -22,18 +26,34 @@ depends_on = None
def upgrade(): def upgrade():
# Create provider_model_credentials table # Create provider_model_credentials table
op.create_table('provider_model_credentials', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), if _is_pg(conn):
sa.Column('provider_name', sa.String(length=255), nullable=False), op.create_table('provider_model_credentials',
sa.Column('model_name', sa.String(length=255), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.Column('model_type', sa.String(length=40), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('credential_name', sa.String(length=255), nullable=False), sa.Column('provider_name', sa.String(length=255), nullable=False),
sa.Column('encrypted_config', sa.Text(), nullable=False), sa.Column('model_name', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('model_type', sa.String(length=40), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('credential_name', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id', name='provider_model_credential_pkey') sa.Column('encrypted_config', sa.Text(), nullable=False),
) sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.PrimaryKeyConstraint('id', name='provider_model_credential_pkey')
)
else:
op.create_table('provider_model_credentials',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuidv7()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('provider_name', sa.String(length=255), nullable=False),
sa.Column('model_name', sa.String(length=255), nullable=False),
sa.Column('model_type', sa.String(length=40), nullable=False),
sa.Column('credential_name', sa.String(length=255), nullable=False),
sa.Column('encrypted_config', models.types.LongText(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='provider_model_credential_pkey')
)
# Create index for provider_model_credentials # Create index for provider_model_credentials
with op.batch_alter_table('provider_model_credentials', schema=None) as batch_op: with op.batch_alter_table('provider_model_credentials', schema=None) as batch_op:
@ -66,31 +86,57 @@ def upgrade():
def migrate_existing_provider_models_data(): def migrate_existing_provider_models_data():
"""migrate provider_models table data to provider_model_credentials""" """migrate provider_models table data to provider_model_credentials"""
conn = op.get_bind()
# Define table structure for data manipulation # Define table structure for data manipulation
provider_models_table = table('provider_models', if _is_pg(conn):
column('id', models.types.StringUUID()), provider_models_table = table('provider_models',
column('tenant_id', models.types.StringUUID()), column('id', models.types.StringUUID()),
column('provider_name', sa.String()), column('tenant_id', models.types.StringUUID()),
column('model_name', sa.String()), column('provider_name', sa.String()),
column('model_type', sa.String()), column('model_name', sa.String()),
column('encrypted_config', sa.Text()), column('model_type', sa.String()),
column('created_at', sa.DateTime()), column('encrypted_config', sa.Text()),
column('updated_at', sa.DateTime()), column('created_at', sa.DateTime()),
column('credential_id', models.types.StringUUID()), column('updated_at', sa.DateTime()),
) column('credential_id', models.types.StringUUID()),
)
else:
provider_models_table = table('provider_models',
column('id', models.types.StringUUID()),
column('tenant_id', models.types.StringUUID()),
column('provider_name', sa.String()),
column('model_name', sa.String()),
column('model_type', sa.String()),
column('encrypted_config', models.types.LongText()),
column('created_at', sa.DateTime()),
column('updated_at', sa.DateTime()),
column('credential_id', models.types.StringUUID()),
)
provider_model_credentials_table = table('provider_model_credentials', if _is_pg(conn):
column('id', models.types.StringUUID()), provider_model_credentials_table = table('provider_model_credentials',
column('tenant_id', models.types.StringUUID()), column('id', models.types.StringUUID()),
column('provider_name', sa.String()), column('tenant_id', models.types.StringUUID()),
column('model_name', sa.String()), column('provider_name', sa.String()),
column('model_type', sa.String()), column('model_name', sa.String()),
column('credential_name', sa.String()), column('model_type', sa.String()),
column('encrypted_config', sa.Text()), column('credential_name', sa.String()),
column('created_at', sa.DateTime()), column('encrypted_config', sa.Text()),
column('updated_at', sa.DateTime()) column('created_at', sa.DateTime()),
) column('updated_at', sa.DateTime())
)
else:
provider_model_credentials_table = table('provider_model_credentials',
column('id', models.types.StringUUID()),
column('tenant_id', models.types.StringUUID()),
column('provider_name', sa.String()),
column('model_name', sa.String()),
column('model_type', sa.String()),
column('credential_name', sa.String()),
column('encrypted_config', models.types.LongText()),
column('created_at', sa.DateTime()),
column('updated_at', sa.DateTime())
)
# Get database connection # Get database connection
@ -137,8 +183,14 @@ def migrate_existing_provider_models_data():
def downgrade(): def downgrade():
# Re-add encrypted_config column to provider_models table # Re-add encrypted_config column to provider_models table
with op.batch_alter_table('provider_models', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('encrypted_config', sa.Text(), nullable=True))
if _is_pg(conn):
with op.batch_alter_table('provider_models', schema=None) as batch_op:
batch_op.add_column(sa.Column('encrypted_config', sa.Text(), nullable=True))
else:
with op.batch_alter_table('provider_models', schema=None) as batch_op:
batch_op.add_column(sa.Column('encrypted_config', models.types.LongText(), nullable=True))
if not context.is_offline_mode(): if not context.is_offline_mode():
# Migrate data back from provider_model_credentials to provider_models # Migrate data back from provider_model_credentials to provider_models

View File

@ -8,6 +8,11 @@ Create Date: 2025-08-20 17:47:17.015695
from alembic import op from alembic import op
import models as models import models as models
import sqlalchemy as sa import sqlalchemy as sa
from libs.uuid_utils import uuidv7
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
@ -19,17 +24,33 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('oauth_provider_apps', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.Column('app_icon', sa.String(length=255), nullable=False), if _is_pg(conn):
sa.Column('app_label', sa.JSON(), server_default='{}', nullable=False), op.create_table('oauth_provider_apps',
sa.Column('client_id', sa.String(length=255), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.Column('client_secret', sa.String(length=255), nullable=False), sa.Column('app_icon', sa.String(length=255), nullable=False),
sa.Column('redirect_uris', sa.JSON(), server_default='[]', nullable=False), sa.Column('app_label', sa.JSON(), server_default='{}', nullable=False),
sa.Column('scope', sa.String(length=255), server_default=sa.text("'read:name read:email read:avatar read:interface_language read:timezone'"), nullable=False), sa.Column('client_id', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('client_secret', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id', name='oauth_provider_app_pkey') sa.Column('redirect_uris', sa.JSON(), server_default='[]', nullable=False),
) sa.Column('scope', sa.String(length=255), server_default=sa.text("'read:name read:email read:avatar read:interface_language read:timezone'"), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='oauth_provider_app_pkey')
)
else:
op.create_table('oauth_provider_apps',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuidv7()), nullable=False),
sa.Column('app_icon', sa.String(length=255), nullable=False),
sa.Column('app_label', sa.JSON(), default='{}', nullable=False),
sa.Column('client_id', sa.String(length=255), nullable=False),
sa.Column('client_secret', sa.String(length=255), nullable=False),
sa.Column('redirect_uris', sa.JSON(), default='[]', nullable=False),
sa.Column('scope', sa.String(length=255), server_default=sa.text("'read:name read:email read:avatar read:interface_language read:timezone'"), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='oauth_provider_app_pkey')
)
with op.batch_alter_table('oauth_provider_apps', schema=None) as batch_op: with op.batch_alter_table('oauth_provider_apps', schema=None) as batch_op:
batch_op.create_index('oauth_provider_app_client_id_idx', ['client_id'], unique=False) batch_op.create_index('oauth_provider_app_client_id_idx', ['client_id'], unique=False)

View File

@ -7,6 +7,10 @@ Create Date: 2025-08-29 10:07:54.163626
""" """
from alembic import op from alembic import op
import models as models import models as models
def _is_pg(conn):
return conn.dialect.name == "postgresql"
import sqlalchemy as sa import sqlalchemy as sa
@ -19,7 +23,12 @@ depends_on = None
def upgrade(): def upgrade():
# Add encrypted_headers column to tool_mcp_providers table # Add encrypted_headers column to tool_mcp_providers table
op.add_column('tool_mcp_providers', sa.Column('encrypted_headers', sa.Text(), nullable=True)) conn = op.get_bind()
if _is_pg(conn):
op.add_column('tool_mcp_providers', sa.Column('encrypted_headers', sa.Text(), nullable=True))
else:
op.add_column('tool_mcp_providers', sa.Column('encrypted_headers', models.types.LongText(), nullable=True))
def downgrade(): def downgrade():

View File

@ -7,6 +7,9 @@ Create Date: 2025-09-11 15:37:17.771298
""" """
from alembic import op from alembic import op
import models as models import models as models
def _is_pg(conn):
return conn.dialect.name == "postgresql"
import sqlalchemy as sa import sqlalchemy as sa
@ -19,8 +22,14 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('providers', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('credential_status', sa.String(length=20), server_default=sa.text("'active'::character varying"), nullable=True))
if _is_pg(conn):
with op.batch_alter_table('providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('credential_status', sa.String(length=20), server_default=sa.text("'active'::character varying"), nullable=True))
else:
with op.batch_alter_table('providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('credential_status', sa.String(length=20), server_default=sa.text("'active'"), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -9,6 +9,11 @@ from alembic import op
import models as models import models as models
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
from libs.uuid_utils import uuidv7
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '68519ad5cd18' revision = '68519ad5cd18'
@ -19,152 +24,314 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('datasource_oauth_params', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.Column('plugin_id', sa.String(length=255), nullable=False), if _is_pg(conn):
sa.Column('provider', sa.String(length=255), nullable=False), op.create_table('datasource_oauth_params',
sa.Column('system_credentials', postgresql.JSONB(astext_type=sa.Text()), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.PrimaryKeyConstraint('id', name='datasource_oauth_config_pkey'), sa.Column('plugin_id', sa.String(length=255), nullable=False),
sa.UniqueConstraint('plugin_id', 'provider', name='datasource_oauth_config_datasource_id_provider_idx') sa.Column('provider', sa.String(length=255), nullable=False),
) sa.Column('system_credentials', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
op.create_table('datasource_oauth_tenant_params', sa.PrimaryKeyConstraint('id', name='datasource_oauth_config_pkey'),
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False), sa.UniqueConstraint('plugin_id', 'provider', name='datasource_oauth_config_datasource_id_provider_idx')
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), )
sa.Column('provider', sa.String(length=255), nullable=False), else:
sa.Column('plugin_id', sa.String(length=255), nullable=False), op.create_table('datasource_oauth_params',
sa.Column('client_params', postgresql.JSONB(astext_type=sa.Text()), nullable=False), sa.Column('id', models.types.StringUUID(), default=lambda: str(uuidv7()), nullable=False),
sa.Column('enabled', sa.Boolean(), nullable=False), sa.Column('plugin_id', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('provider', sa.String(length=255), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('system_credentials', sa.JSON(), nullable=False),
sa.PrimaryKeyConstraint('id', name='datasource_oauth_tenant_config_pkey'), sa.PrimaryKeyConstraint('id', name='datasource_oauth_config_pkey'),
sa.UniqueConstraint('tenant_id', 'plugin_id', 'provider', name='datasource_oauth_tenant_config_unique') sa.UniqueConstraint('plugin_id', 'provider', name='datasource_oauth_config_datasource_id_provider_idx')
) )
op.create_table('datasource_providers', if _is_pg(conn):
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False), op.create_table('datasource_oauth_tenant_params',
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('provider', sa.String(length=255), nullable=False), sa.Column('provider', sa.String(length=255), nullable=False),
sa.Column('plugin_id', sa.String(length=255), nullable=False), sa.Column('plugin_id', sa.String(length=255), nullable=False),
sa.Column('auth_type', sa.String(length=255), nullable=False), sa.Column('client_params', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.Column('encrypted_credentials', postgresql.JSONB(astext_type=sa.Text()), nullable=False), sa.Column('enabled', sa.Boolean(), nullable=False),
sa.Column('avatar_url', sa.Text(), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.Column('is_default', sa.Boolean(), server_default=sa.text('false'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.Column('expires_at', sa.Integer(), server_default='-1', nullable=False), sa.PrimaryKeyConstraint('id', name='datasource_oauth_tenant_config_pkey'),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.UniqueConstraint('tenant_id', 'plugin_id', 'provider', name='datasource_oauth_tenant_config_unique')
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), )
sa.PrimaryKeyConstraint('id', name='datasource_provider_pkey'), else:
sa.UniqueConstraint('tenant_id', 'plugin_id', 'provider', 'name', name='datasource_provider_unique_name') op.create_table('datasource_oauth_tenant_params',
) sa.Column('id', models.types.StringUUID(), default=lambda: str(uuidv7()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('provider', sa.String(length=255), nullable=False),
sa.Column('plugin_id', sa.String(length=255), nullable=False),
sa.Column('client_params', sa.JSON(), nullable=False),
sa.Column('enabled', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='datasource_oauth_tenant_config_pkey'),
sa.UniqueConstraint('tenant_id', 'plugin_id', 'provider', name='datasource_oauth_tenant_config_unique')
)
if _is_pg(conn):
op.create_table('datasource_providers',
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('provider', sa.String(length=255), nullable=False),
sa.Column('plugin_id', sa.String(length=255), nullable=False),
sa.Column('auth_type', sa.String(length=255), nullable=False),
sa.Column('encrypted_credentials', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.Column('avatar_url', sa.Text(), nullable=True),
sa.Column('is_default', sa.Boolean(), server_default=sa.text('false'), nullable=False),
sa.Column('expires_at', sa.Integer(), server_default='-1', nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.PrimaryKeyConstraint('id', name='datasource_provider_pkey'),
sa.UniqueConstraint('tenant_id', 'plugin_id', 'provider', 'name', name='datasource_provider_unique_name')
)
else:
op.create_table('datasource_providers',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuidv7()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('provider', sa.String(length=128), nullable=False),
sa.Column('plugin_id', sa.String(length=255), nullable=False),
sa.Column('auth_type', sa.String(length=255), nullable=False),
sa.Column('encrypted_credentials', sa.JSON(), nullable=False),
sa.Column('avatar_url', models.types.LongText(), nullable=True),
sa.Column('is_default', sa.Boolean(), server_default=sa.text('false'), nullable=False),
sa.Column('expires_at', sa.Integer(), server_default='-1', nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='datasource_provider_pkey'),
sa.UniqueConstraint('tenant_id', 'plugin_id', 'provider', 'name', name='datasource_provider_unique_name')
)
with op.batch_alter_table('datasource_providers', schema=None) as batch_op: with op.batch_alter_table('datasource_providers', schema=None) as batch_op:
batch_op.create_index('datasource_provider_auth_type_provider_idx', ['tenant_id', 'plugin_id', 'provider'], unique=False) batch_op.create_index('datasource_provider_auth_type_provider_idx', ['tenant_id', 'plugin_id', 'provider'], unique=False)
op.create_table('document_pipeline_execution_logs', if _is_pg(conn):
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False), op.create_table('document_pipeline_execution_logs',
sa.Column('pipeline_id', models.types.StringUUID(), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.Column('document_id', models.types.StringUUID(), nullable=False), sa.Column('pipeline_id', models.types.StringUUID(), nullable=False),
sa.Column('datasource_type', sa.String(length=255), nullable=False), sa.Column('document_id', models.types.StringUUID(), nullable=False),
sa.Column('datasource_info', sa.Text(), nullable=False), sa.Column('datasource_type', sa.String(length=255), nullable=False),
sa.Column('datasource_node_id', sa.String(length=255), nullable=False), sa.Column('datasource_info', sa.Text(), nullable=False),
sa.Column('input_data', sa.JSON(), nullable=False), sa.Column('datasource_node_id', sa.String(length=255), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=True), sa.Column('input_data', sa.JSON(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('created_by', models.types.StringUUID(), nullable=True),
sa.PrimaryKeyConstraint('id', name='document_pipeline_execution_log_pkey') sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
) sa.PrimaryKeyConstraint('id', name='document_pipeline_execution_log_pkey')
)
else:
op.create_table('document_pipeline_execution_logs',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuidv7()), nullable=False),
sa.Column('pipeline_id', models.types.StringUUID(), nullable=False),
sa.Column('document_id', models.types.StringUUID(), nullable=False),
sa.Column('datasource_type', sa.String(length=255), nullable=False),
sa.Column('datasource_info', models.types.LongText(), nullable=False),
sa.Column('datasource_node_id', sa.String(length=255), nullable=False),
sa.Column('input_data', sa.JSON(), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='document_pipeline_execution_log_pkey')
)
with op.batch_alter_table('document_pipeline_execution_logs', schema=None) as batch_op: with op.batch_alter_table('document_pipeline_execution_logs', schema=None) as batch_op:
batch_op.create_index('document_pipeline_execution_logs_document_id_idx', ['document_id'], unique=False) batch_op.create_index('document_pipeline_execution_logs_document_id_idx', ['document_id'], unique=False)
op.create_table('pipeline_built_in_templates', if _is_pg(conn):
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False), op.create_table('pipeline_built_in_templates',
sa.Column('name', sa.String(length=255), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.Column('description', sa.Text(), nullable=False), sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('chunk_structure', sa.String(length=255), nullable=False), sa.Column('description', sa.Text(), nullable=False),
sa.Column('icon', sa.JSON(), nullable=False), sa.Column('chunk_structure', sa.String(length=255), nullable=False),
sa.Column('yaml_content', sa.Text(), nullable=False), sa.Column('icon', sa.JSON(), nullable=False),
sa.Column('copyright', sa.String(length=255), nullable=False), sa.Column('yaml_content', sa.Text(), nullable=False),
sa.Column('privacy_policy', sa.String(length=255), nullable=False), sa.Column('copyright', sa.String(length=255), nullable=False),
sa.Column('position', sa.Integer(), nullable=False), sa.Column('privacy_policy', sa.String(length=255), nullable=False),
sa.Column('install_count', sa.Integer(), nullable=False), sa.Column('position', sa.Integer(), nullable=False),
sa.Column('language', sa.String(length=255), nullable=False), sa.Column('install_count', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('language', sa.String(length=255), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.Column('updated_by', models.types.StringUUID(), nullable=True), sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.PrimaryKeyConstraint('id', name='pipeline_built_in_template_pkey') sa.Column('updated_by', models.types.StringUUID(), nullable=True),
) sa.PrimaryKeyConstraint('id', name='pipeline_built_in_template_pkey')
op.create_table('pipeline_customized_templates', )
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False), else:
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), op.create_table('pipeline_built_in_templates',
sa.Column('name', sa.String(length=255), nullable=False), sa.Column('id', models.types.StringUUID(), default=lambda: str(uuidv7()), nullable=False),
sa.Column('description', sa.Text(), nullable=False), sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('chunk_structure', sa.String(length=255), nullable=False), sa.Column('description', models.types.LongText(), nullable=False),
sa.Column('icon', sa.JSON(), nullable=False), sa.Column('chunk_structure', sa.String(length=255), nullable=False),
sa.Column('position', sa.Integer(), nullable=False), sa.Column('icon', sa.JSON(), nullable=False),
sa.Column('yaml_content', sa.Text(), nullable=False), sa.Column('yaml_content', models.types.LongText(), nullable=False),
sa.Column('install_count', sa.Integer(), nullable=False), sa.Column('copyright', sa.String(length=255), nullable=False),
sa.Column('language', sa.String(length=255), nullable=False), sa.Column('privacy_policy', sa.String(length=255), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False), sa.Column('position', sa.Integer(), nullable=False),
sa.Column('updated_by', models.types.StringUUID(), nullable=True), sa.Column('install_count', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('language', sa.String(length=255), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='pipeline_customized_template_pkey') sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
) sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('updated_by', models.types.StringUUID(), nullable=True),
sa.PrimaryKeyConstraint('id', name='pipeline_built_in_template_pkey')
)
if _is_pg(conn):
op.create_table('pipeline_customized_templates',
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('description', sa.Text(), nullable=False),
sa.Column('chunk_structure', sa.String(length=255), nullable=False),
sa.Column('icon', sa.JSON(), nullable=False),
sa.Column('position', sa.Integer(), nullable=False),
sa.Column('yaml_content', sa.Text(), nullable=False),
sa.Column('install_count', sa.Integer(), nullable=False),
sa.Column('language', sa.String(length=255), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('updated_by', models.types.StringUUID(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.PrimaryKeyConstraint('id', name='pipeline_customized_template_pkey')
)
else:
# MySQL: Use compatible syntax
op.create_table('pipeline_customized_templates',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuidv7()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('description', models.types.LongText(), nullable=False),
sa.Column('chunk_structure', sa.String(length=255), nullable=False),
sa.Column('icon', sa.JSON(), nullable=False),
sa.Column('position', sa.Integer(), nullable=False),
sa.Column('yaml_content', models.types.LongText(), nullable=False),
sa.Column('install_count', sa.Integer(), nullable=False),
sa.Column('language', sa.String(length=255), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('updated_by', models.types.StringUUID(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='pipeline_customized_template_pkey')
)
with op.batch_alter_table('pipeline_customized_templates', schema=None) as batch_op: with op.batch_alter_table('pipeline_customized_templates', schema=None) as batch_op:
batch_op.create_index('pipeline_customized_template_tenant_idx', ['tenant_id'], unique=False) batch_op.create_index('pipeline_customized_template_tenant_idx', ['tenant_id'], unique=False)
op.create_table('pipeline_recommended_plugins', if _is_pg(conn):
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False), op.create_table('pipeline_recommended_plugins',
sa.Column('plugin_id', sa.Text(), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.Column('provider_name', sa.Text(), nullable=False), sa.Column('plugin_id', sa.Text(), nullable=False),
sa.Column('position', sa.Integer(), nullable=False), sa.Column('provider_name', sa.Text(), nullable=False),
sa.Column('active', sa.Boolean(), nullable=False), sa.Column('position', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('active', sa.Boolean(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.PrimaryKeyConstraint('id', name='pipeline_recommended_plugin_pkey') sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
) sa.PrimaryKeyConstraint('id', name='pipeline_recommended_plugin_pkey')
op.create_table('pipelines', )
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False), else:
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), op.create_table('pipeline_recommended_plugins',
sa.Column('name', sa.String(length=255), nullable=False), sa.Column('id', models.types.StringUUID(), default=lambda: str(uuidv7()), nullable=False),
sa.Column('description', sa.Text(), server_default=sa.text("''::character varying"), nullable=False), sa.Column('plugin_id', models.types.LongText(), nullable=False),
sa.Column('workflow_id', models.types.StringUUID(), nullable=True), sa.Column('provider_name', models.types.LongText(), nullable=False),
sa.Column('is_public', sa.Boolean(), server_default=sa.text('false'), nullable=False), sa.Column('position', sa.Integer(), nullable=False),
sa.Column('is_published', sa.Boolean(), server_default=sa.text('false'), nullable=False), sa.Column('active', sa.Boolean(), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_by', models.types.StringUUID(), nullable=True), sa.PrimaryKeyConstraint('id', name='pipeline_recommended_plugin_pkey')
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), )
sa.PrimaryKeyConstraint('id', name='pipeline_pkey') if _is_pg(conn):
) op.create_table('pipelines',
op.create_table('workflow_draft_variable_files', sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False, comment='The tenant to which the WorkflowDraftVariableFile belongs, referencing Tenant.id'), sa.Column('description', sa.Text(), server_default=sa.text("''::character varying"), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False, comment='The application to which the WorkflowDraftVariableFile belongs, referencing App.id'), sa.Column('workflow_id', models.types.StringUUID(), nullable=True),
sa.Column('user_id', models.types.StringUUID(), nullable=False, comment='The owner to of the WorkflowDraftVariableFile, referencing Account.id'), sa.Column('is_public', sa.Boolean(), server_default=sa.text('false'), nullable=False),
sa.Column('upload_file_id', models.types.StringUUID(), nullable=False, comment='Reference to UploadFile containing the large variable data'), sa.Column('is_published', sa.Boolean(), server_default=sa.text('false'), nullable=False),
sa.Column('size', sa.BigInteger(), nullable=False, comment='Size of the original variable content in bytes'), sa.Column('created_by', models.types.StringUUID(), nullable=True),
sa.Column('length', sa.Integer(), nullable=True, comment='Length of the original variable content. For array and array-like types, this represents the number of elements. For object types, it indicates the number of keys. For other types, the value is NULL.'), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.Column('value_type', sa.String(20), nullable=False), sa.Column('updated_by', models.types.StringUUID(), nullable=True),
sa.PrimaryKeyConstraint('id', name=op.f('workflow_draft_variable_files_pkey')) sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
) sa.PrimaryKeyConstraint('id', name='pipeline_pkey')
op.create_table('workflow_node_execution_offload', )
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False), else:
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), op.create_table('pipelines',
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), sa.Column('id', models.types.StringUUID(), default=lambda: str(uuidv7()), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('node_execution_id', models.types.StringUUID(), nullable=True), sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('type', sa.String(20), nullable=False), sa.Column('description', models.types.LongText(), default=sa.text("''"), nullable=False),
sa.Column('file_id', models.types.StringUUID(), nullable=False), sa.Column('workflow_id', models.types.StringUUID(), nullable=True),
sa.PrimaryKeyConstraint('id', name=op.f('workflow_node_execution_offload_pkey')), sa.Column('is_public', sa.Boolean(), server_default=sa.text('false'), nullable=False),
sa.UniqueConstraint('node_execution_id', 'type', name=op.f('workflow_node_execution_offload_node_execution_id_key')) sa.Column('is_published', sa.Boolean(), server_default=sa.text('false'), nullable=False),
) sa.Column('created_by', models.types.StringUUID(), nullable=True),
with op.batch_alter_table('datasets', schema=None) as batch_op: sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
batch_op.add_column(sa.Column('keyword_number', sa.Integer(), server_default=sa.text('10'), nullable=True)) sa.Column('updated_by', models.types.StringUUID(), nullable=True),
batch_op.add_column(sa.Column('icon_info', postgresql.JSONB(astext_type=sa.Text()), nullable=True)) sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
batch_op.add_column(sa.Column('runtime_mode', sa.String(length=255), server_default=sa.text("'general'::character varying"), nullable=True)) sa.PrimaryKeyConstraint('id', name='pipeline_pkey')
batch_op.add_column(sa.Column('pipeline_id', models.types.StringUUID(), nullable=True)) )
batch_op.add_column(sa.Column('chunk_structure', sa.String(length=255), nullable=True)) if _is_pg(conn):
batch_op.add_column(sa.Column('enable_api', sa.Boolean(), server_default=sa.text('true'), nullable=False)) op.create_table('workflow_draft_variable_files',
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False, comment='The tenant to which the WorkflowDraftVariableFile belongs, referencing Tenant.id'),
sa.Column('app_id', models.types.StringUUID(), nullable=False, comment='The application to which the WorkflowDraftVariableFile belongs, referencing App.id'),
sa.Column('user_id', models.types.StringUUID(), nullable=False, comment='The owner to of the WorkflowDraftVariableFile, referencing Account.id'),
sa.Column('upload_file_id', models.types.StringUUID(), nullable=False, comment='Reference to UploadFile containing the large variable data'),
sa.Column('size', sa.BigInteger(), nullable=False, comment='Size of the original variable content in bytes'),
sa.Column('length', sa.Integer(), nullable=True, comment='Length of the original variable content. For array and array-like types, this represents the number of elements. For object types, it indicates the number of keys. For other types, the value is NULL.'),
sa.Column('value_type', sa.String(20), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('workflow_draft_variable_files_pkey'))
)
else:
op.create_table('workflow_draft_variable_files',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuidv7()), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False, comment='The tenant to which the WorkflowDraftVariableFile belongs, referencing Tenant.id'),
sa.Column('app_id', models.types.StringUUID(), nullable=False, comment='The application to which the WorkflowDraftVariableFile belongs, referencing App.id'),
sa.Column('user_id', models.types.StringUUID(), nullable=False, comment='The owner to of the WorkflowDraftVariableFile, referencing Account.id'),
sa.Column('upload_file_id', models.types.StringUUID(), nullable=False, comment='Reference to UploadFile containing the large variable data'),
sa.Column('size', sa.BigInteger(), nullable=False, comment='Size of the original variable content in bytes'),
sa.Column('length', sa.Integer(), nullable=True, comment='Length of the original variable content. For array and array-like types, this represents the number of elements. For object types, it indicates the number of keys. For other types, the value is NULL.'),
sa.Column('value_type', sa.String(20), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('workflow_draft_variable_files_pkey'))
)
if _is_pg(conn):
op.create_table('workflow_node_execution_offload',
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuidv7()'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('node_execution_id', models.types.StringUUID(), nullable=True),
sa.Column('type', sa.String(20), nullable=False),
sa.Column('file_id', models.types.StringUUID(), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('workflow_node_execution_offload_pkey')),
sa.UniqueConstraint('node_execution_id', 'type', name=op.f('workflow_node_execution_offload_node_execution_id_key'))
)
else:
op.create_table('workflow_node_execution_offload',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuidv7()), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('node_execution_id', models.types.StringUUID(), nullable=True),
sa.Column('type', sa.String(20), nullable=False),
sa.Column('file_id', models.types.StringUUID(), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('workflow_node_execution_offload_pkey')),
sa.UniqueConstraint('node_execution_id', 'type', name=op.f('workflow_node_execution_offload_node_execution_id_key'))
)
if _is_pg(conn):
with op.batch_alter_table('datasets', schema=None) as batch_op:
batch_op.add_column(sa.Column('keyword_number', sa.Integer(), server_default=sa.text('10'), nullable=True))
batch_op.add_column(sa.Column('icon_info', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
batch_op.add_column(sa.Column('runtime_mode', sa.String(length=255), server_default=sa.text("'general'::character varying"), nullable=True))
batch_op.add_column(sa.Column('pipeline_id', models.types.StringUUID(), nullable=True))
batch_op.add_column(sa.Column('chunk_structure', sa.String(length=255), nullable=True))
batch_op.add_column(sa.Column('enable_api', sa.Boolean(), server_default=sa.text('true'), nullable=False))
else:
with op.batch_alter_table('datasets', schema=None) as batch_op:
batch_op.add_column(sa.Column('keyword_number', sa.Integer(), server_default=sa.text('10'), nullable=True))
batch_op.add_column(sa.Column('icon_info', sa.JSON(), nullable=True))
batch_op.add_column(sa.Column('runtime_mode', sa.String(length=255), server_default=sa.text("'general'"), nullable=True))
batch_op.add_column(sa.Column('pipeline_id', models.types.StringUUID(), nullable=True))
batch_op.add_column(sa.Column('chunk_structure', sa.String(length=255), nullable=True))
batch_op.add_column(sa.Column('enable_api', sa.Boolean(), server_default=sa.text('true'), nullable=False))
with op.batch_alter_table('workflow_draft_variables', schema=None) as batch_op: with op.batch_alter_table('workflow_draft_variables', schema=None) as batch_op:
batch_op.add_column(sa.Column('file_id', models.types.StringUUID(), nullable=True, comment='Reference to WorkflowDraftVariableFile if variable is offloaded to external storage')) batch_op.add_column(sa.Column('file_id', models.types.StringUUID(), nullable=True, comment='Reference to WorkflowDraftVariableFile if variable is offloaded to external storage'))
@ -175,9 +342,12 @@ def upgrade():
comment='Indicates whether the current value is the default for a conversation variable. Always `FALSE` for other types of variables.',) comment='Indicates whether the current value is the default for a conversation variable. Always `FALSE` for other types of variables.',)
) )
batch_op.create_index('workflow_draft_variable_file_id_idx', ['file_id'], unique=False) batch_op.create_index('workflow_draft_variable_file_id_idx', ['file_id'], unique=False)
if _is_pg(conn):
with op.batch_alter_table('workflows', schema=None) as batch_op: with op.batch_alter_table('workflows', schema=None) as batch_op:
batch_op.add_column(sa.Column('rag_pipeline_variables', sa.Text(), server_default='{}', nullable=False)) batch_op.add_column(sa.Column('rag_pipeline_variables', sa.Text(), server_default='{}', nullable=False))
else:
with op.batch_alter_table('workflows', schema=None) as batch_op:
batch_op.add_column(sa.Column('rag_pipeline_variables', models.types.LongText(), default='{}', nullable=False))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,6 +7,10 @@ Create Date: 2025-10-21 14:30:28.566192
""" """
from alembic import op from alembic import op
import models as models import models as models
def _is_pg(conn):
return conn.dialect.name == "postgresql"
import sqlalchemy as sa import sqlalchemy as sa
@ -29,8 +33,15 @@ def upgrade():
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('pipeline_built_in_templates', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('created_by', sa.UUID(), autoincrement=False, nullable=False))
batch_op.add_column(sa.Column('updated_by', sa.UUID(), autoincrement=False, nullable=True)) if _is_pg(conn):
with op.batch_alter_table('pipeline_built_in_templates', schema=None) as batch_op:
batch_op.add_column(sa.Column('created_by', sa.UUID(), autoincrement=False, nullable=False))
batch_op.add_column(sa.Column('updated_by', sa.UUID(), autoincrement=False, nullable=True))
else:
with op.batch_alter_table('pipeline_built_in_templates', schema=None) as batch_op:
batch_op.add_column(sa.Column('created_by', models.types.StringUUID(), autoincrement=False, nullable=False))
batch_op.add_column(sa.Column('updated_by', models.types.StringUUID(), autoincrement=False, nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -9,7 +9,10 @@ Create Date: 2025-10-22 16:11:31.805407
from alembic import op from alembic import op
import models as models import models as models
import sqlalchemy as sa import sqlalchemy as sa
from libs.uuid_utils import uuidv7
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = "03f8dcbc611e" revision = "03f8dcbc611e"
@ -19,19 +22,32 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table( if _is_pg(op.get_context().bind):
"workflow_pauses", op.create_table(
sa.Column("workflow_id", models.types.StringUUID(), nullable=False), "workflow_pauses",
sa.Column("workflow_run_id", models.types.StringUUID(), nullable=False), sa.Column("workflow_id", models.types.StringUUID(), nullable=False),
sa.Column("resumed_at", sa.DateTime(), nullable=True), sa.Column("workflow_run_id", models.types.StringUUID(), nullable=False),
sa.Column("state_object_key", sa.String(length=255), nullable=False), sa.Column("resumed_at", sa.DateTime(), nullable=True),
sa.Column("id", models.types.StringUUID(), server_default=sa.text("uuidv7()"), nullable=False), sa.Column("state_object_key", sa.String(length=255), nullable=False),
sa.Column("created_at", sa.DateTime(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False), sa.Column("id", models.types.StringUUID(), server_default=sa.text("uuidv7()"), nullable=False),
sa.Column("updated_at", sa.DateTime(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False), sa.Column("created_at", sa.DateTime(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("workflow_pauses_pkey")), sa.Column("updated_at", sa.DateTime(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False),
sa.UniqueConstraint("workflow_run_id", name=op.f("workflow_pauses_workflow_run_id_key")), sa.PrimaryKeyConstraint("id", name=op.f("workflow_pauses_pkey")),
) sa.UniqueConstraint("workflow_run_id", name=op.f("workflow_pauses_workflow_run_id_key")),
)
else:
op.create_table(
"workflow_pauses",
sa.Column("workflow_id", models.types.StringUUID(), nullable=False),
sa.Column("workflow_run_id", models.types.StringUUID(), nullable=False),
sa.Column("resumed_at", sa.DateTime(), nullable=True),
sa.Column("state_object_key", sa.String(length=255), nullable=False),
sa.Column("id", models.types.StringUUID(), default=lambda: str(uuidv7()), nullable=False),
sa.Column("created_at", sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column("updated_at", sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("workflow_pauses_pkey")),
sa.UniqueConstraint("workflow_run_id", name=op.f("workflow_pauses_workflow_run_id_key")),
)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -0,0 +1,202 @@
"""empty message
Revision ID: f26e7cdbb0fe
Revises: 03f8dcbc611e
Create Date: 2025-10-31 15:05:38.637798
"""
from alembic import op
import models as models
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql, mysql
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic.
revision = 'f26e7cdbb0fe'
down_revision = '03f8dcbc611e'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
if _is_pg(conn):
with op.batch_alter_table('data_source_oauth_bindings', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('source_info_idx'), postgresql_using='gin')
batch_op.alter_column('source_info',
existing_type=postgresql.JSONB(astext_type=sa.Text()),
type_=sa.JSON(),
existing_nullable=False)
with op.batch_alter_table('datasets', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('retrieval_model_idx'), postgresql_using='gin')
batch_op.alter_column('retrieval_model',
existing_type=postgresql.JSONB(astext_type=sa.Text()),
type_=sa.JSON(),
existing_nullable=True)
batch_op.alter_column('icon_info',
existing_type=postgresql.JSONB(astext_type=sa.Text()),
type_=sa.JSON(),
existing_nullable=True)
with op.batch_alter_table('datasource_oauth_params', schema=None) as batch_op:
batch_op.alter_column('system_credentials',
existing_type=postgresql.JSONB(astext_type=sa.Text()),
type_=sa.JSON(),
existing_nullable=False)
with op.batch_alter_table('datasource_oauth_tenant_params', schema=None) as batch_op:
batch_op.alter_column('client_params',
existing_type=postgresql.JSONB(astext_type=sa.Text()),
type_=sa.JSON(),
existing_nullable=False)
with op.batch_alter_table('datasource_providers', schema=None) as batch_op:
batch_op.alter_column('provider',
existing_type=sa.VARCHAR(length=255),
type_=sa.String(length=128),
existing_nullable=False)
batch_op.alter_column('encrypted_credentials',
existing_type=postgresql.JSONB(astext_type=sa.Text()),
type_=sa.JSON(),
existing_nullable=False)
with op.batch_alter_table('documents', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('document_metadata_idx'), postgresql_using='gin')
batch_op.alter_column('doc_metadata',
existing_type=postgresql.JSONB(astext_type=sa.Text()),
type_=sa.JSON(),
existing_nullable=True)
with op.batch_alter_table('external_knowledge_bindings', schema=None) as batch_op:
batch_op.alter_column('external_knowledge_id',
existing_type=sa.TEXT(),
type_=sa.String(length=512),
existing_nullable=False)
with op.batch_alter_table('providers', schema=None) as batch_op:
batch_op.drop_column('credential_status')
with op.batch_alter_table('tenant_plugin_auto_upgrade_strategies', schema=None) as batch_op:
op.execute("""
ALTER TABLE tenant_plugin_auto_upgrade_strategies
ALTER COLUMN exclude_plugins TYPE JSON
USING array_to_json(exclude_plugins)
""")
op.execute("""
ALTER TABLE tenant_plugin_auto_upgrade_strategies
ALTER COLUMN include_plugins TYPE JSON
USING array_to_json(include_plugins)
""")
with op.batch_alter_table('tool_oauth_tenant_clients', schema=None) as batch_op:
batch_op.alter_column('plugin_id',
existing_type=sa.VARCHAR(length=512),
type_=sa.String(length=255),
existing_nullable=False)
else:
with op.batch_alter_table('providers', schema=None) as batch_op:
batch_op.drop_column('credential_status')
with op.batch_alter_table('workflows', schema=None) as batch_op:
batch_op.alter_column('updated_at',
existing_type=sa.TIMESTAMP(),
type_=sa.DateTime(),
existing_nullable=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
if _is_pg(conn):
with op.batch_alter_table('tool_oauth_tenant_clients', schema=None) as batch_op:
batch_op.alter_column('plugin_id',
existing_type=sa.String(length=255),
type_=sa.VARCHAR(length=512),
existing_nullable=False)
with op.batch_alter_table('tenant_plugin_auto_upgrade_strategies', schema=None) as batch_op:
op.execute("""
ALTER TABLE tenant_plugin_auto_upgrade_strategies
ALTER COLUMN exclude_plugins TYPE JSON
USING array_to_json(exclude_plugins)
""")
op.execute("""
ALTER TABLE tenant_plugin_auto_upgrade_strategies
ALTER COLUMN include_plugins TYPE JSON
USING array_to_json(include_plugins)
""")
with op.batch_alter_table('providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('credential_status', sa.VARCHAR(length=20), server_default=sa.text("'active'::character varying"), autoincrement=False, nullable=True))
with op.batch_alter_table('external_knowledge_bindings', schema=None) as batch_op:
batch_op.alter_column('external_knowledge_id',
existing_type=sa.String(length=512),
type_=sa.TEXT(),
existing_nullable=False)
with op.batch_alter_table('documents', schema=None) as batch_op:
batch_op.alter_column('doc_metadata',
existing_type=sa.JSON(),
type_=postgresql.JSONB(astext_type=sa.Text()),
existing_nullable=True)
batch_op.create_index(batch_op.f('document_metadata_idx'), ['doc_metadata'], unique=False, postgresql_using='gin')
with op.batch_alter_table('datasource_providers', schema=None) as batch_op:
batch_op.alter_column('encrypted_credentials',
existing_type=sa.JSON(),
type_=postgresql.JSONB(astext_type=sa.Text()),
existing_nullable=False)
batch_op.alter_column('provider',
existing_type=sa.String(length=128),
type_=sa.VARCHAR(length=255),
existing_nullable=False)
with op.batch_alter_table('datasource_oauth_tenant_params', schema=None) as batch_op:
batch_op.alter_column('client_params',
existing_type=sa.JSON(),
type_=postgresql.JSONB(astext_type=sa.Text()),
existing_nullable=False)
with op.batch_alter_table('datasource_oauth_params', schema=None) as batch_op:
batch_op.alter_column('system_credentials',
existing_type=sa.JSON(),
type_=postgresql.JSONB(astext_type=sa.Text()),
existing_nullable=False)
with op.batch_alter_table('datasets', schema=None) as batch_op:
batch_op.alter_column('icon_info',
existing_type=sa.JSON(),
type_=postgresql.JSONB(astext_type=sa.Text()),
existing_nullable=True)
batch_op.alter_column('retrieval_model',
existing_type=sa.JSON(),
type_=postgresql.JSONB(astext_type=sa.Text()),
existing_nullable=True)
batch_op.create_index(batch_op.f('retrieval_model_idx'), ['retrieval_model'], unique=False, postgresql_using='gin')
with op.batch_alter_table('data_source_oauth_bindings', schema=None) as batch_op:
batch_op.alter_column('source_info',
existing_type=sa.JSON(),
type_=postgresql.JSONB(astext_type=sa.Text()),
existing_nullable=False)
batch_op.create_index(batch_op.f('source_info_idx'), ['source_info'], unique=False, postgresql_using='gin')
else:
with op.batch_alter_table('workflows', schema=None) as batch_op:
batch_op.alter_column('updated_at',
existing_type=sa.DateTime(),
type_=sa.TIMESTAMP(),
existing_nullable=False)
with op.batch_alter_table('providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('credential_status', mysql.VARCHAR(collation='utf8mb4_unicode_ci', length=20), server_default=sa.text("'active'"), nullable=True))
# ### end Alembic commands ###

View File

@ -8,6 +8,12 @@ Create Date: 2024-01-18 08:46:37.302657
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '23db93619b9d' revision = '23db93619b9d'
down_revision = '8ae9bc661daa' down_revision = '8ae9bc661daa'
@ -17,8 +23,14 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('message_files', sa.Text(), nullable=True))
if _is_pg(conn):
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op:
batch_op.add_column(sa.Column('message_files', sa.Text(), nullable=True))
else:
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op:
batch_op.add_column(sa.Column('message_files', models.types.LongText(), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,8 +7,15 @@ Create Date: 2023-12-14 11:26:12.287264
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '246ba09cbbdb' revision = '246ba09cbbdb'
down_revision = '714aafe25d39' down_revision = '714aafe25d39'
@ -18,17 +25,33 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('app_annotation_settings', conn = op.get_bind()
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('app_id', postgresql.UUID(), nullable=False), if _is_pg(conn):
sa.Column('score_threshold', sa.Float(), server_default=sa.text('0'), nullable=False), op.create_table('app_annotation_settings',
sa.Column('collection_binding_id', postgresql.UUID(), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('created_user_id', postgresql.UUID(), nullable=False), sa.Column('app_id', postgresql.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('score_threshold', sa.Float(), server_default=sa.text('0'), nullable=False),
sa.Column('updated_user_id', postgresql.UUID(), nullable=False), sa.Column('collection_binding_id', postgresql.UUID(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('created_user_id', postgresql.UUID(), nullable=False),
sa.PrimaryKeyConstraint('id', name='app_annotation_settings_pkey') sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
) sa.Column('updated_user_id', postgresql.UUID(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='app_annotation_settings_pkey')
)
else:
op.create_table('app_annotation_settings',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('score_threshold', sa.Float(), server_default=sa.text('0'), nullable=False),
sa.Column('collection_binding_id', models.types.StringUUID(), nullable=False),
sa.Column('created_user_id', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_user_id', models.types.StringUUID(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='app_annotation_settings_pkey')
)
with op.batch_alter_table('app_annotation_settings', schema=None) as batch_op: with op.batch_alter_table('app_annotation_settings', schema=None) as batch_op:
batch_op.create_index('app_annotation_settings_app_idx', ['app_id'], unique=False) batch_op.create_index('app_annotation_settings_app_idx', ['app_id'], unique=False)
@ -40,8 +63,14 @@ def upgrade():
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('app_model_configs', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('annotation_reply', sa.TEXT(), autoincrement=False, nullable=True))
if _is_pg(conn):
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('annotation_reply', sa.TEXT(), autoincrement=False, nullable=True))
else:
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('annotation_reply', models.types.LongText(), autoincrement=False, nullable=True))
with op.batch_alter_table('app_annotation_settings', schema=None) as batch_op: with op.batch_alter_table('app_annotation_settings', schema=None) as batch_op:
batch_op.drop_index('app_annotation_settings_app_idx') batch_op.drop_index('app_annotation_settings_app_idx')

View File

@ -10,6 +10,10 @@ from alembic import op
import models as models import models as models
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '2a3aebbbf4bb' revision = '2a3aebbbf4bb'
down_revision = 'c031d46af369' down_revision = 'c031d46af369'
@ -19,8 +23,14 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('apps', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('tracing', sa.Text(), nullable=True))
if _is_pg(conn):
with op.batch_alter_table('apps', schema=None) as batch_op:
batch_op.add_column(sa.Column('tracing', sa.Text(), nullable=True))
else:
with op.batch_alter_table('apps', schema=None) as batch_op:
batch_op.add_column(sa.Column('tracing', models.types.LongText(), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -9,6 +9,12 @@ import sqlalchemy as sa
from alembic import op from alembic import op
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '2e9819ca5b28' revision = '2e9819ca5b28'
down_revision = 'ab23c11305d4' down_revision = 'ab23c11305d4'
@ -18,19 +24,35 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('api_tokens', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('tenant_id', postgresql.UUID(), nullable=True))
batch_op.create_index('api_token_tenant_idx', ['tenant_id', 'type'], unique=False) if _is_pg(conn):
batch_op.drop_column('dataset_id') with op.batch_alter_table('api_tokens', schema=None) as batch_op:
batch_op.add_column(sa.Column('tenant_id', postgresql.UUID(), nullable=True))
batch_op.create_index('api_token_tenant_idx', ['tenant_id', 'type'], unique=False)
batch_op.drop_column('dataset_id')
else:
with op.batch_alter_table('api_tokens', schema=None) as batch_op:
batch_op.add_column(sa.Column('tenant_id', models.types.StringUUID(), nullable=True))
batch_op.create_index('api_token_tenant_idx', ['tenant_id', 'type'], unique=False)
batch_op.drop_column('dataset_id')
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('api_tokens', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('dataset_id', postgresql.UUID(), autoincrement=False, nullable=True))
batch_op.drop_index('api_token_tenant_idx') if _is_pg(conn):
batch_op.drop_column('tenant_id') with op.batch_alter_table('api_tokens', schema=None) as batch_op:
batch_op.add_column(sa.Column('dataset_id', postgresql.UUID(), autoincrement=False, nullable=True))
batch_op.drop_index('api_token_tenant_idx')
batch_op.drop_column('tenant_id')
else:
with op.batch_alter_table('api_tokens', schema=None) as batch_op:
batch_op.add_column(sa.Column('dataset_id', models.types.StringUUID(), autoincrement=False, nullable=True))
batch_op.drop_index('api_token_tenant_idx')
batch_op.drop_column('tenant_id')
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,6 +8,12 @@ Create Date: 2024-01-24 10:58:15.644445
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '380c6aa5a70d' revision = '380c6aa5a70d'
down_revision = 'dfb3b7f477da' down_revision = 'dfb3b7f477da'
@ -17,8 +23,14 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('tool_labels_str', sa.Text(), server_default=sa.text("'{}'::text"), nullable=False))
if _is_pg(conn):
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op:
batch_op.add_column(sa.Column('tool_labels_str', sa.Text(), server_default=sa.text("'{}'::text"), nullable=False))
else:
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op:
batch_op.add_column(sa.Column('tool_labels_str', models.types.LongText(), default=sa.text("'{}'"), nullable=False))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,9 +7,14 @@ Create Date: 2024-05-14 09:27:18.857890
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
import models.types import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '3b18fea55204' revision = '3b18fea55204'
down_revision = '7bdef072e63a' down_revision = '7bdef072e63a'
@ -19,13 +24,24 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('tool_label_bindings', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tool_id', sa.String(length=64), nullable=False), if _is_pg(conn):
sa.Column('tool_type', sa.String(length=40), nullable=False), op.create_table('tool_label_bindings',
sa.Column('label_name', sa.String(length=40), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_label_bind_pkey') sa.Column('tool_id', sa.String(length=64), nullable=False),
) sa.Column('tool_type', sa.String(length=40), nullable=False),
sa.Column('label_name', sa.String(length=40), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_label_bind_pkey')
)
else:
op.create_table('tool_label_bindings',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tool_id', sa.String(length=64), nullable=False),
sa.Column('tool_type', sa.String(length=40), nullable=False),
sa.Column('label_name', sa.String(length=40), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_label_bind_pkey')
)
with op.batch_alter_table('tool_workflow_providers', schema=None) as batch_op: with op.batch_alter_table('tool_workflow_providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('privacy_policy', sa.String(length=255), server_default='', nullable=True)) batch_op.add_column(sa.Column('privacy_policy', sa.String(length=255), server_default='', nullable=True))

View File

@ -7,8 +7,15 @@ Create Date: 2024-04-11 06:17:34.278594
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '3c7cac9521c6' revision = '3c7cac9521c6'
down_revision = 'c3311b089690' down_revision = 'c3311b089690'
@ -18,28 +25,54 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('tag_bindings', conn = op.get_bind()
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', postgresql.UUID(), nullable=True), if _is_pg(conn):
sa.Column('tag_id', postgresql.UUID(), nullable=True), op.create_table('tag_bindings',
sa.Column('target_id', postgresql.UUID(), nullable=True), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('created_by', postgresql.UUID(), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('tag_id', postgresql.UUID(), nullable=True),
sa.PrimaryKeyConstraint('id', name='tag_binding_pkey') sa.Column('target_id', postgresql.UUID(), nullable=True),
) sa.Column('created_by', postgresql.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='tag_binding_pkey')
)
else:
op.create_table('tag_bindings',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=True),
sa.Column('tag_id', models.types.StringUUID(), nullable=True),
sa.Column('target_id', models.types.StringUUID(), nullable=True),
sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tag_binding_pkey')
)
with op.batch_alter_table('tag_bindings', schema=None) as batch_op: with op.batch_alter_table('tag_bindings', schema=None) as batch_op:
batch_op.create_index('tag_bind_tag_id_idx', ['tag_id'], unique=False) batch_op.create_index('tag_bind_tag_id_idx', ['tag_id'], unique=False)
batch_op.create_index('tag_bind_target_id_idx', ['target_id'], unique=False) batch_op.create_index('tag_bind_target_id_idx', ['target_id'], unique=False)
op.create_table('tags', if _is_pg(conn):
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False), op.create_table('tags',
sa.Column('tenant_id', postgresql.UUID(), nullable=True), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('type', sa.String(length=16), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=True),
sa.Column('name', sa.String(length=255), nullable=False), sa.Column('type', sa.String(length=16), nullable=False),
sa.Column('created_by', postgresql.UUID(), nullable=False), sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('created_by', postgresql.UUID(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tag_pkey') sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
) sa.PrimaryKeyConstraint('id', name='tag_pkey')
)
else:
op.create_table('tags',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=True),
sa.Column('type', sa.String(length=16), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tag_pkey')
)
with op.batch_alter_table('tags', schema=None) as batch_op: with op.batch_alter_table('tags', schema=None) as batch_op:
batch_op.create_index('tag_name_idx', ['name'], unique=False) batch_op.create_index('tag_name_idx', ['name'], unique=False)
batch_op.create_index('tag_type_idx', ['type'], unique=False) batch_op.create_index('tag_type_idx', ['type'], unique=False)

View File

@ -7,8 +7,15 @@ Create Date: 2024-01-05 15:26:25.117551
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '3ef9b2b6bee6' revision = '3ef9b2b6bee6'
down_revision = '89c7899ca936' down_revision = '89c7899ca936'
@ -18,44 +25,96 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('tool_api_providers', conn = op.get_bind()
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('name', sa.String(length=40), nullable=False), if _is_pg(conn):
sa.Column('schema', sa.Text(), nullable=False), # PostgreSQL: Keep original syntax
sa.Column('schema_type_str', sa.String(length=40), nullable=False), op.create_table('tool_api_providers',
sa.Column('user_id', postgresql.UUID(), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', postgresql.UUID(), nullable=False), sa.Column('name', sa.String(length=40), nullable=False),
sa.Column('description_str', sa.Text(), nullable=False), sa.Column('schema', sa.Text(), nullable=False),
sa.Column('tools_str', sa.Text(), nullable=False), sa.Column('schema_type_str', sa.String(length=40), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_api_provider_pkey') sa.Column('user_id', postgresql.UUID(), nullable=False),
) sa.Column('tenant_id', postgresql.UUID(), nullable=False),
op.create_table('tool_builtin_providers', sa.Column('description_str', sa.Text(), nullable=False),
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False), sa.Column('tools_str', sa.Text(), nullable=False),
sa.Column('tenant_id', postgresql.UUID(), nullable=True), sa.PrimaryKeyConstraint('id', name='tool_api_provider_pkey')
sa.Column('user_id', postgresql.UUID(), nullable=False), )
sa.Column('provider', sa.String(length=40), nullable=False), else:
sa.Column('encrypted_credentials', sa.Text(), nullable=True), # MySQL: Use compatible syntax
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), op.create_table('tool_api_providers',
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_builtin_provider_pkey'), sa.Column('name', sa.String(length=40), nullable=False),
sa.UniqueConstraint('tenant_id', 'provider', name='unique_builtin_tool_provider') sa.Column('schema', models.types.LongText(), nullable=False),
) sa.Column('schema_type_str', sa.String(length=40), nullable=False),
op.create_table('tool_published_apps', sa.Column('user_id', models.types.StringUUID(), nullable=False),
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('app_id', postgresql.UUID(), nullable=False), sa.Column('description_str', models.types.LongText(), nullable=False),
sa.Column('user_id', postgresql.UUID(), nullable=False), sa.Column('tools_str', models.types.LongText(), nullable=False),
sa.Column('description', sa.Text(), nullable=False), sa.PrimaryKeyConstraint('id', name='tool_api_provider_pkey')
sa.Column('llm_description', sa.Text(), nullable=False), )
sa.Column('query_description', sa.Text(), nullable=False), if _is_pg(conn):
sa.Column('query_name', sa.String(length=40), nullable=False), # PostgreSQL: Keep original syntax
sa.Column('tool_name', sa.String(length=40), nullable=False), op.create_table('tool_builtin_providers',
sa.Column('author', sa.String(length=40), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=True),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('user_id', postgresql.UUID(), nullable=False),
sa.ForeignKeyConstraint(['app_id'], ['apps.id'], ), sa.Column('provider', sa.String(length=40), nullable=False),
sa.PrimaryKeyConstraint('id', name='published_app_tool_pkey'), sa.Column('encrypted_credentials', sa.Text(), nullable=True),
sa.UniqueConstraint('app_id', 'user_id', name='unique_published_app_tool') sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
) sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_builtin_provider_pkey'),
sa.UniqueConstraint('tenant_id', 'provider', name='unique_builtin_tool_provider')
)
else:
# MySQL: Use compatible syntax
op.create_table('tool_builtin_providers',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=True),
sa.Column('user_id', models.types.StringUUID(), nullable=False),
sa.Column('provider', sa.String(length=40), nullable=False),
sa.Column('encrypted_credentials', models.types.LongText(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_builtin_provider_pkey'),
sa.UniqueConstraint('tenant_id', 'provider', name='unique_builtin_tool_provider')
)
if _is_pg(conn):
# PostgreSQL: Keep original syntax
op.create_table('tool_published_apps',
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('app_id', postgresql.UUID(), nullable=False),
sa.Column('user_id', postgresql.UUID(), nullable=False),
sa.Column('description', sa.Text(), nullable=False),
sa.Column('llm_description', sa.Text(), nullable=False),
sa.Column('query_description', sa.Text(), nullable=False),
sa.Column('query_name', sa.String(length=40), nullable=False),
sa.Column('tool_name', sa.String(length=40), nullable=False),
sa.Column('author', sa.String(length=40), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.ForeignKeyConstraint(['app_id'], ['apps.id'], ),
sa.PrimaryKeyConstraint('id', name='published_app_tool_pkey'),
sa.UniqueConstraint('app_id', 'user_id', name='unique_published_app_tool')
)
else:
# MySQL: Use compatible syntax
op.create_table('tool_published_apps',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('user_id', models.types.StringUUID(), nullable=False),
sa.Column('description', models.types.LongText(), nullable=False),
sa.Column('llm_description', models.types.LongText(), nullable=False),
sa.Column('query_description', models.types.LongText(), nullable=False),
sa.Column('query_name', sa.String(length=40), nullable=False),
sa.Column('tool_name', sa.String(length=40), nullable=False),
sa.Column('author', sa.String(length=40), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.ForeignKeyConstraint(['app_id'], ['apps.id'], ),
sa.PrimaryKeyConstraint('id', name='published_app_tool_pkey'),
sa.UniqueConstraint('app_id', 'user_id', name='unique_published_app_tool')
)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -9,6 +9,12 @@ import sqlalchemy as sa
from alembic import op from alembic import op
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '42e85ed5564d' revision = '42e85ed5564d'
down_revision = 'f9107f83abab' down_revision = 'f9107f83abab'
@ -18,31 +24,59 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('conversations', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('app_model_config_id',
existing_type=postgresql.UUID(), if _is_pg(conn):
nullable=True) with op.batch_alter_table('conversations', schema=None) as batch_op:
batch_op.alter_column('model_provider', batch_op.alter_column('app_model_config_id',
existing_type=sa.VARCHAR(length=255), existing_type=postgresql.UUID(),
nullable=True) nullable=True)
batch_op.alter_column('model_id', batch_op.alter_column('model_provider',
existing_type=sa.VARCHAR(length=255), existing_type=sa.VARCHAR(length=255),
nullable=True) nullable=True)
batch_op.alter_column('model_id',
existing_type=sa.VARCHAR(length=255),
nullable=True)
else:
with op.batch_alter_table('conversations', schema=None) as batch_op:
batch_op.alter_column('app_model_config_id',
existing_type=models.types.StringUUID(),
nullable=True)
batch_op.alter_column('model_provider',
existing_type=sa.VARCHAR(length=255),
nullable=True)
batch_op.alter_column('model_id',
existing_type=sa.VARCHAR(length=255),
nullable=True)
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('conversations', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('model_id',
existing_type=sa.VARCHAR(length=255), if _is_pg(conn):
nullable=False) with op.batch_alter_table('conversations', schema=None) as batch_op:
batch_op.alter_column('model_provider', batch_op.alter_column('model_id',
existing_type=sa.VARCHAR(length=255), existing_type=sa.VARCHAR(length=255),
nullable=False) nullable=False)
batch_op.alter_column('app_model_config_id', batch_op.alter_column('model_provider',
existing_type=postgresql.UUID(), existing_type=sa.VARCHAR(length=255),
nullable=False) nullable=False)
batch_op.alter_column('app_model_config_id',
existing_type=postgresql.UUID(),
nullable=False)
else:
with op.batch_alter_table('conversations', schema=None) as batch_op:
batch_op.alter_column('model_id',
existing_type=sa.VARCHAR(length=255),
nullable=False)
batch_op.alter_column('model_provider',
existing_type=sa.VARCHAR(length=255),
nullable=False)
batch_op.alter_column('app_model_config_id',
existing_type=models.types.StringUUID(),
nullable=False)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,8 +7,15 @@ Create Date: 2024-01-15 11:37:16.782718
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '4823da1d26cf' revision = '4823da1d26cf'
down_revision = '053da0c1d756' down_revision = '053da0c1d756'
@ -18,16 +25,30 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('tool_files', conn = op.get_bind()
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('user_id', postgresql.UUID(), nullable=False), if _is_pg(conn):
sa.Column('tenant_id', postgresql.UUID(), nullable=False), op.create_table('tool_files',
sa.Column('conversation_id', postgresql.UUID(), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('file_key', sa.String(length=255), nullable=False), sa.Column('user_id', postgresql.UUID(), nullable=False),
sa.Column('mimetype', sa.String(length=255), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=False),
sa.Column('original_url', sa.String(length=255), nullable=True), sa.Column('conversation_id', postgresql.UUID(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_file_pkey') sa.Column('file_key', sa.String(length=255), nullable=False),
) sa.Column('mimetype', sa.String(length=255), nullable=False),
sa.Column('original_url', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('id', name='tool_file_pkey')
)
else:
op.create_table('tool_files',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('user_id', models.types.StringUUID(), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('conversation_id', models.types.StringUUID(), nullable=False),
sa.Column('file_key', sa.String(length=255), nullable=False),
sa.Column('mimetype', sa.String(length=255), nullable=False),
sa.Column('original_url', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('id', name='tool_file_pkey')
)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,6 +8,12 @@ Create Date: 2024-01-12 03:42:27.362415
from alembic import op from alembic import op
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '4829e54d2fee' revision = '4829e54d2fee'
down_revision = '114eed84c228' down_revision = '114eed84c228'
@ -17,19 +23,39 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('message_chain_id',
existing_type=postgresql.UUID(), if _is_pg(conn):
nullable=True) # PostgreSQL: Keep original syntax
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op:
batch_op.alter_column('message_chain_id',
existing_type=postgresql.UUID(),
nullable=True)
else:
# MySQL: Use compatible syntax
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op:
batch_op.alter_column('message_chain_id',
existing_type=models.types.StringUUID(),
nullable=True)
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('message_chain_id',
existing_type=postgresql.UUID(), if _is_pg(conn):
nullable=False) # PostgreSQL: Keep original syntax
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op:
batch_op.alter_column('message_chain_id',
existing_type=postgresql.UUID(),
nullable=False)
else:
# MySQL: Use compatible syntax
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op:
batch_op.alter_column('message_chain_id',
existing_type=models.types.StringUUID(),
nullable=False)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,6 +8,10 @@ Create Date: 2023-08-28 20:58:50.077056
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '4bcffcd64aa4' revision = '4bcffcd64aa4'
down_revision = '853f9b9cd3b6' down_revision = '853f9b9cd3b6'
@ -17,29 +21,55 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('datasets', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('embedding_model',
existing_type=sa.VARCHAR(length=255), if _is_pg(conn):
nullable=True, with op.batch_alter_table('datasets', schema=None) as batch_op:
existing_server_default=sa.text("'text-embedding-ada-002'::character varying")) batch_op.alter_column('embedding_model',
batch_op.alter_column('embedding_model_provider', existing_type=sa.VARCHAR(length=255),
existing_type=sa.VARCHAR(length=255), nullable=True,
nullable=True, existing_server_default=sa.text("'text-embedding-ada-002'::character varying"))
existing_server_default=sa.text("'openai'::character varying")) batch_op.alter_column('embedding_model_provider',
existing_type=sa.VARCHAR(length=255),
nullable=True,
existing_server_default=sa.text("'openai'::character varying"))
else:
with op.batch_alter_table('datasets', schema=None) as batch_op:
batch_op.alter_column('embedding_model',
existing_type=sa.VARCHAR(length=255),
nullable=True,
existing_server_default=sa.text("'text-embedding-ada-002'"))
batch_op.alter_column('embedding_model_provider',
existing_type=sa.VARCHAR(length=255),
nullable=True,
existing_server_default=sa.text("'openai'"))
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('datasets', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('embedding_model_provider',
existing_type=sa.VARCHAR(length=255), if _is_pg(conn):
nullable=False, with op.batch_alter_table('datasets', schema=None) as batch_op:
existing_server_default=sa.text("'openai'::character varying")) batch_op.alter_column('embedding_model_provider',
batch_op.alter_column('embedding_model', existing_type=sa.VARCHAR(length=255),
existing_type=sa.VARCHAR(length=255), nullable=False,
nullable=False, existing_server_default=sa.text("'openai'::character varying"))
existing_server_default=sa.text("'text-embedding-ada-002'::character varying")) batch_op.alter_column('embedding_model',
existing_type=sa.VARCHAR(length=255),
nullable=False,
existing_server_default=sa.text("'text-embedding-ada-002'::character varying"))
else:
with op.batch_alter_table('datasets', schema=None) as batch_op:
batch_op.alter_column('embedding_model_provider',
existing_type=sa.VARCHAR(length=255),
nullable=False,
existing_server_default=sa.text("'openai'"))
batch_op.alter_column('embedding_model',
existing_type=sa.VARCHAR(length=255),
nullable=False,
existing_server_default=sa.text("'text-embedding-ada-002'"))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,9 +7,14 @@ Create Date: 2024-05-10 12:08:09.812736
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
import models.types import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '4e99a8df00ff' revision = '4e99a8df00ff'
down_revision = '64a70a7aab8b' down_revision = '64a70a7aab8b'
@ -19,34 +24,67 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('load_balancing_model_configs', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), if _is_pg(conn):
sa.Column('provider_name', sa.String(length=255), nullable=False), op.create_table('load_balancing_model_configs',
sa.Column('model_name', sa.String(length=255), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('model_type', sa.String(length=40), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False), sa.Column('provider_name', sa.String(length=255), nullable=False),
sa.Column('encrypted_config', sa.Text(), nullable=True), sa.Column('model_name', sa.String(length=255), nullable=False),
sa.Column('enabled', sa.Boolean(), server_default=sa.text('true'), nullable=False), sa.Column('model_type', sa.String(length=40), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('encrypted_config', sa.Text(), nullable=True),
sa.PrimaryKeyConstraint('id', name='load_balancing_model_config_pkey') sa.Column('enabled', sa.Boolean(), server_default=sa.text('true'), nullable=False),
) sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='load_balancing_model_config_pkey')
)
else:
op.create_table('load_balancing_model_configs',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('provider_name', sa.String(length=255), nullable=False),
sa.Column('model_name', sa.String(length=255), nullable=False),
sa.Column('model_type', sa.String(length=40), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('encrypted_config', models.types.LongText(), nullable=True),
sa.Column('enabled', sa.Boolean(), server_default=sa.text('true'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='load_balancing_model_config_pkey')
)
with op.batch_alter_table('load_balancing_model_configs', schema=None) as batch_op: with op.batch_alter_table('load_balancing_model_configs', schema=None) as batch_op:
batch_op.create_index('load_balancing_model_config_tenant_provider_model_idx', ['tenant_id', 'provider_name', 'model_type'], unique=False) batch_op.create_index('load_balancing_model_config_tenant_provider_model_idx', ['tenant_id', 'provider_name', 'model_type'], unique=False)
op.create_table('provider_model_settings', if _is_pg(conn):
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False), op.create_table('provider_model_settings',
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('provider_name', sa.String(length=255), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('model_name', sa.String(length=255), nullable=False), sa.Column('provider_name', sa.String(length=255), nullable=False),
sa.Column('model_type', sa.String(length=40), nullable=False), sa.Column('model_name', sa.String(length=255), nullable=False),
sa.Column('enabled', sa.Boolean(), server_default=sa.text('true'), nullable=False), sa.Column('model_type', sa.String(length=40), nullable=False),
sa.Column('load_balancing_enabled', sa.Boolean(), server_default=sa.text('false'), nullable=False), sa.Column('enabled', sa.Boolean(), server_default=sa.text('true'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('load_balancing_enabled', sa.Boolean(), server_default=sa.text('false'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='provider_model_setting_pkey') sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
) sa.PrimaryKeyConstraint('id', name='provider_model_setting_pkey')
)
else:
op.create_table('provider_model_settings',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('provider_name', sa.String(length=255), nullable=False),
sa.Column('model_name', sa.String(length=255), nullable=False),
sa.Column('model_type', sa.String(length=40), nullable=False),
sa.Column('enabled', sa.Boolean(), server_default=sa.text('true'), nullable=False),
sa.Column('load_balancing_enabled', sa.Boolean(), server_default=sa.text('false'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='provider_model_setting_pkey')
)
with op.batch_alter_table('provider_model_settings', schema=None) as batch_op: with op.batch_alter_table('provider_model_settings', schema=None) as batch_op:
batch_op.create_index('provider_model_setting_tenant_provider_model_idx', ['tenant_id', 'provider_name', 'model_type'], unique=False) batch_op.create_index('provider_model_setting_tenant_provider_model_idx', ['tenant_id', 'provider_name', 'model_type'], unique=False)

View File

@ -8,6 +8,10 @@ Create Date: 2023-08-11 14:38:15.499460
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '5022897aaceb' revision = '5022897aaceb'
down_revision = 'bf0aec5ba2cf' down_revision = 'bf0aec5ba2cf'
@ -17,10 +21,20 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('embeddings', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('model_name', sa.String(length=40), server_default=sa.text("'text-embedding-ada-002'::character varying"), nullable=False))
batch_op.drop_constraint('embedding_hash_idx', type_='unique') if _is_pg(conn):
batch_op.create_unique_constraint('embedding_hash_idx', ['model_name', 'hash']) # PostgreSQL: Keep original syntax
with op.batch_alter_table('embeddings', schema=None) as batch_op:
batch_op.add_column(sa.Column('model_name', sa.String(length=40), server_default=sa.text("'text-embedding-ada-002'::character varying"), nullable=False))
batch_op.drop_constraint('embedding_hash_idx', type_='unique')
batch_op.create_unique_constraint('embedding_hash_idx', ['model_name', 'hash'])
else:
# MySQL: Use compatible syntax
with op.batch_alter_table('embeddings', schema=None) as batch_op:
batch_op.add_column(sa.Column('model_name', sa.String(length=40), server_default=sa.text("'text-embedding-ada-002'"), nullable=False))
batch_op.drop_constraint('embedding_hash_idx', type_='unique')
batch_op.create_unique_constraint('embedding_hash_idx', ['model_name', 'hash'])
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -10,6 +10,10 @@ from alembic import op
import models as models import models as models
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '53bf8af60645' revision = '53bf8af60645'
down_revision = '8e5588e6412e' down_revision = '8e5588e6412e'
@ -19,23 +23,43 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('embeddings', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('provider_name',
existing_type=sa.VARCHAR(length=40), if _is_pg(conn):
type_=sa.String(length=255), with op.batch_alter_table('embeddings', schema=None) as batch_op:
existing_nullable=False, batch_op.alter_column('provider_name',
existing_server_default=sa.text("''::character varying")) existing_type=sa.VARCHAR(length=40),
type_=sa.String(length=255),
existing_nullable=False,
existing_server_default=sa.text("''::character varying"))
else:
with op.batch_alter_table('embeddings', schema=None) as batch_op:
batch_op.alter_column('provider_name',
existing_type=sa.VARCHAR(length=40),
type_=sa.String(length=255),
existing_nullable=False,
existing_server_default=sa.text("''"))
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('embeddings', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('provider_name',
existing_type=sa.String(length=255), if _is_pg(conn):
type_=sa.VARCHAR(length=40), with op.batch_alter_table('embeddings', schema=None) as batch_op:
existing_nullable=False, batch_op.alter_column('provider_name',
existing_server_default=sa.text("''::character varying")) existing_type=sa.String(length=255),
type_=sa.VARCHAR(length=40),
existing_nullable=False,
existing_server_default=sa.text("''::character varying"))
else:
with op.batch_alter_table('embeddings', schema=None) as batch_op:
batch_op.alter_column('provider_name',
existing_type=sa.String(length=255),
type_=sa.VARCHAR(length=40),
existing_nullable=False,
existing_server_default=sa.text("''"))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,6 +8,12 @@ Create Date: 2024-03-14 04:54:56.679506
from alembic import op from alembic import op
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '563cf8bf777b' revision = '563cf8bf777b'
down_revision = 'b5429b71023c' down_revision = 'b5429b71023c'
@ -17,19 +23,35 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tool_files', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('conversation_id',
existing_type=postgresql.UUID(), if _is_pg(conn):
nullable=True) with op.batch_alter_table('tool_files', schema=None) as batch_op:
batch_op.alter_column('conversation_id',
existing_type=postgresql.UUID(),
nullable=True)
else:
with op.batch_alter_table('tool_files', schema=None) as batch_op:
batch_op.alter_column('conversation_id',
existing_type=models.types.StringUUID(),
nullable=True)
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tool_files', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('conversation_id',
existing_type=postgresql.UUID(), if _is_pg(conn):
nullable=False) with op.batch_alter_table('tool_files', schema=None) as batch_op:
batch_op.alter_column('conversation_id',
existing_type=postgresql.UUID(),
nullable=False)
else:
with op.batch_alter_table('tool_files', schema=None) as batch_op:
batch_op.alter_column('conversation_id',
existing_type=models.types.StringUUID(),
nullable=False)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,6 +8,10 @@ Create Date: 2023-06-15 13:33:00.357467
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '614f77cecc48' revision = '614f77cecc48'
down_revision = 'a45f4dfde53b' down_revision = 'a45f4dfde53b'
@ -17,8 +21,14 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('accounts', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('last_active_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False))
if _is_pg(conn):
with op.batch_alter_table('accounts', schema=None) as batch_op:
batch_op.add_column(sa.Column('last_active_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False))
else:
with op.batch_alter_table('accounts', schema=None) as batch_op:
batch_op.add_column(sa.Column('last_active_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False))
# ### end Alembic commands ### # ### end Alembic commands ###

File diff suppressed because it is too large Load Diff

View File

@ -7,8 +7,15 @@ Create Date: 2023-09-06 16:51:27.385844
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '6dcb43972bdc' revision = '6dcb43972bdc'
down_revision = '4bcffcd64aa4' down_revision = '4bcffcd64aa4'
@ -18,27 +25,53 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('dataset_retriever_resources', conn = op.get_bind()
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('message_id', postgresql.UUID(), nullable=False), if _is_pg(conn):
sa.Column('position', sa.Integer(), nullable=False), op.create_table('dataset_retriever_resources',
sa.Column('dataset_id', postgresql.UUID(), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('dataset_name', sa.Text(), nullable=False), sa.Column('message_id', postgresql.UUID(), nullable=False),
sa.Column('document_id', postgresql.UUID(), nullable=False), sa.Column('position', sa.Integer(), nullable=False),
sa.Column('document_name', sa.Text(), nullable=False), sa.Column('dataset_id', postgresql.UUID(), nullable=False),
sa.Column('data_source_type', sa.Text(), nullable=False), sa.Column('dataset_name', sa.Text(), nullable=False),
sa.Column('segment_id', postgresql.UUID(), nullable=False), sa.Column('document_id', postgresql.UUID(), nullable=False),
sa.Column('score', sa.Float(), nullable=True), sa.Column('document_name', sa.Text(), nullable=False),
sa.Column('content', sa.Text(), nullable=False), sa.Column('data_source_type', sa.Text(), nullable=False),
sa.Column('hit_count', sa.Integer(), nullable=True), sa.Column('segment_id', postgresql.UUID(), nullable=False),
sa.Column('word_count', sa.Integer(), nullable=True), sa.Column('score', sa.Float(), nullable=True),
sa.Column('segment_position', sa.Integer(), nullable=True), sa.Column('content', sa.Text(), nullable=False),
sa.Column('index_node_hash', sa.Text(), nullable=True), sa.Column('hit_count', sa.Integer(), nullable=True),
sa.Column('retriever_from', sa.Text(), nullable=False), sa.Column('word_count', sa.Integer(), nullable=True),
sa.Column('created_by', postgresql.UUID(), nullable=False), sa.Column('segment_position', sa.Integer(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('index_node_hash', sa.Text(), nullable=True),
sa.PrimaryKeyConstraint('id', name='dataset_retriever_resource_pkey') sa.Column('retriever_from', sa.Text(), nullable=False),
) sa.Column('created_by', postgresql.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.PrimaryKeyConstraint('id', name='dataset_retriever_resource_pkey')
)
else:
op.create_table('dataset_retriever_resources',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('message_id', models.types.StringUUID(), nullable=False),
sa.Column('position', sa.Integer(), nullable=False),
sa.Column('dataset_id', models.types.StringUUID(), nullable=False),
sa.Column('dataset_name', models.types.LongText(), nullable=False),
sa.Column('document_id', models.types.StringUUID(), nullable=False),
sa.Column('document_name', models.types.LongText(), nullable=False),
sa.Column('data_source_type', models.types.LongText(), nullable=False),
sa.Column('segment_id', models.types.StringUUID(), nullable=False),
sa.Column('score', sa.Float(), nullable=True),
sa.Column('content', models.types.LongText(), nullable=False),
sa.Column('hit_count', sa.Integer(), nullable=True),
sa.Column('word_count', sa.Integer(), nullable=True),
sa.Column('segment_position', sa.Integer(), nullable=True),
sa.Column('index_node_hash', models.types.LongText(), nullable=True),
sa.Column('retriever_from', models.types.LongText(), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='dataset_retriever_resource_pkey')
)
with op.batch_alter_table('dataset_retriever_resources', schema=None) as batch_op: with op.batch_alter_table('dataset_retriever_resources', schema=None) as batch_op:
batch_op.create_index('dataset_retriever_resource_message_id_idx', ['message_id'], unique=False) batch_op.create_index('dataset_retriever_resource_message_id_idx', ['message_id'], unique=False)

View File

@ -7,8 +7,15 @@ Create Date: 2023-09-13 22:16:48.027810
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '6e2cfb077b04' revision = '6e2cfb077b04'
down_revision = '77e83833755c' down_revision = '77e83833755c'
@ -18,19 +25,36 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('dataset_collection_bindings', conn = op.get_bind()
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('provider_name', sa.String(length=40), nullable=False), if _is_pg(conn):
sa.Column('model_name', sa.String(length=40), nullable=False), op.create_table('dataset_collection_bindings',
sa.Column('collection_name', sa.String(length=64), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('provider_name', sa.String(length=40), nullable=False),
sa.PrimaryKeyConstraint('id', name='dataset_collection_bindings_pkey') sa.Column('model_name', sa.String(length=40), nullable=False),
) sa.Column('collection_name', sa.String(length=64), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='dataset_collection_bindings_pkey')
)
else:
op.create_table('dataset_collection_bindings',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('provider_name', sa.String(length=40), nullable=False),
sa.Column('model_name', sa.String(length=40), nullable=False),
sa.Column('collection_name', sa.String(length=64), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='dataset_collection_bindings_pkey')
)
with op.batch_alter_table('dataset_collection_bindings', schema=None) as batch_op: with op.batch_alter_table('dataset_collection_bindings', schema=None) as batch_op:
batch_op.create_index('provider_model_name_idx', ['provider_name', 'model_name'], unique=False) batch_op.create_index('provider_model_name_idx', ['provider_name', 'model_name'], unique=False)
with op.batch_alter_table('datasets', schema=None) as batch_op: if _is_pg(conn):
batch_op.add_column(sa.Column('collection_binding_id', postgresql.UUID(), nullable=True)) with op.batch_alter_table('datasets', schema=None) as batch_op:
batch_op.add_column(sa.Column('collection_binding_id', postgresql.UUID(), nullable=True))
else:
with op.batch_alter_table('datasets', schema=None) as batch_op:
batch_op.add_column(sa.Column('collection_binding_id', models.types.StringUUID(), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,6 +8,12 @@ Create Date: 2023-12-14 06:38:02.972527
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '714aafe25d39' revision = '714aafe25d39'
down_revision = 'f2a6fc85e260' down_revision = 'f2a6fc85e260'
@ -17,9 +23,16 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('app_annotation_hit_histories', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('annotation_question', sa.Text(), nullable=False))
batch_op.add_column(sa.Column('annotation_content', sa.Text(), nullable=False)) if _is_pg(conn):
with op.batch_alter_table('app_annotation_hit_histories', schema=None) as batch_op:
batch_op.add_column(sa.Column('annotation_question', sa.Text(), nullable=False))
batch_op.add_column(sa.Column('annotation_content', sa.Text(), nullable=False))
else:
with op.batch_alter_table('app_annotation_hit_histories', schema=None) as batch_op:
batch_op.add_column(sa.Column('annotation_question', models.types.LongText(), nullable=False))
batch_op.add_column(sa.Column('annotation_content', models.types.LongText(), nullable=False))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,6 +8,12 @@ Create Date: 2023-09-06 17:26:40.311927
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '77e83833755c' revision = '77e83833755c'
down_revision = '6dcb43972bdc' down_revision = '6dcb43972bdc'
@ -17,8 +23,14 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('app_model_configs', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('retriever_resource', sa.Text(), nullable=True))
if _is_pg(conn):
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('retriever_resource', sa.Text(), nullable=True))
else:
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('retriever_resource', models.types.LongText(), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,9 +7,14 @@ Create Date: 2024-05-14 07:31:29.702766
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
import models.types import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '7b45942e39bb' revision = '7b45942e39bb'
down_revision = '4e99a8df00ff' down_revision = '4e99a8df00ff'
@ -19,44 +24,75 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('data_source_api_key_auth_bindings', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), if _is_pg(conn):
sa.Column('category', sa.String(length=255), nullable=False), # PostgreSQL: Keep original syntax
sa.Column('provider', sa.String(length=255), nullable=False), op.create_table('data_source_api_key_auth_bindings',
sa.Column('credentials', sa.Text(), nullable=True), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('category', sa.String(length=255), nullable=False),
sa.Column('disabled', sa.Boolean(), server_default=sa.text('false'), nullable=True), sa.Column('provider', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id', name='data_source_api_key_auth_binding_pkey') sa.Column('credentials', sa.Text(), nullable=True),
) sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('disabled', sa.Boolean(), server_default=sa.text('false'), nullable=True),
sa.PrimaryKeyConstraint('id', name='data_source_api_key_auth_binding_pkey')
)
else:
# MySQL: Use compatible syntax
op.create_table('data_source_api_key_auth_bindings',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('category', sa.String(length=255), nullable=False),
sa.Column('provider', sa.String(length=255), nullable=False),
sa.Column('credentials', models.types.LongText(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('disabled', sa.Boolean(), server_default=sa.text('false'), nullable=True),
sa.PrimaryKeyConstraint('id', name='data_source_api_key_auth_binding_pkey')
)
with op.batch_alter_table('data_source_api_key_auth_bindings', schema=None) as batch_op: with op.batch_alter_table('data_source_api_key_auth_bindings', schema=None) as batch_op:
batch_op.create_index('data_source_api_key_auth_binding_provider_idx', ['provider'], unique=False) batch_op.create_index('data_source_api_key_auth_binding_provider_idx', ['provider'], unique=False)
batch_op.create_index('data_source_api_key_auth_binding_tenant_id_idx', ['tenant_id'], unique=False) batch_op.create_index('data_source_api_key_auth_binding_tenant_id_idx', ['tenant_id'], unique=False)
with op.batch_alter_table('data_source_bindings', schema=None) as batch_op: with op.batch_alter_table('data_source_bindings', schema=None) as batch_op:
batch_op.drop_index('source_binding_tenant_id_idx') batch_op.drop_index('source_binding_tenant_id_idx')
batch_op.drop_index('source_info_idx') if _is_pg(conn):
batch_op.drop_index('source_info_idx', postgresql_using='gin')
else:
pass
op.rename_table('data_source_bindings', 'data_source_oauth_bindings') op.rename_table('data_source_bindings', 'data_source_oauth_bindings')
with op.batch_alter_table('data_source_oauth_bindings', schema=None) as batch_op: with op.batch_alter_table('data_source_oauth_bindings', schema=None) as batch_op:
batch_op.create_index('source_binding_tenant_id_idx', ['tenant_id'], unique=False) batch_op.create_index('source_binding_tenant_id_idx', ['tenant_id'], unique=False)
batch_op.create_index('source_info_idx', ['source_info'], unique=False, postgresql_using='gin') if _is_pg(conn):
batch_op.create_index('source_info_idx', ['source_info'], unique=False, postgresql_using='gin')
else:
pass
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
with op.batch_alter_table('data_source_oauth_bindings', schema=None) as batch_op: with op.batch_alter_table('data_source_oauth_bindings', schema=None) as batch_op:
batch_op.drop_index('source_info_idx', postgresql_using='gin') if _is_pg(conn):
batch_op.drop_index('source_info_idx', postgresql_using='gin')
else:
pass
batch_op.drop_index('source_binding_tenant_id_idx') batch_op.drop_index('source_binding_tenant_id_idx')
op.rename_table('data_source_oauth_bindings', 'data_source_bindings') op.rename_table('data_source_oauth_bindings', 'data_source_bindings')
with op.batch_alter_table('data_source_bindings', schema=None) as batch_op: with op.batch_alter_table('data_source_bindings', schema=None) as batch_op:
batch_op.create_index('source_info_idx', ['source_info'], unique=False) if _is_pg(conn):
batch_op.create_index('source_info_idx', ['source_info'], unique=False, postgresql_using='gin')
else:
pass
batch_op.create_index('source_binding_tenant_id_idx', ['tenant_id'], unique=False) batch_op.create_index('source_binding_tenant_id_idx', ['tenant_id'], unique=False)
with op.batch_alter_table('data_source_api_key_auth_bindings', schema=None) as batch_op: with op.batch_alter_table('data_source_api_key_auth_bindings', schema=None) as batch_op:

View File

@ -7,9 +7,14 @@ Create Date: 2024-05-04 09:47:19.366961
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
import models.types import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '7bdef072e63a' revision = '7bdef072e63a'
down_revision = '5fda94355fce' down_revision = '5fda94355fce'
@ -19,21 +24,42 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('tool_workflow_providers', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('name', sa.String(length=40), nullable=False), if _is_pg(conn):
sa.Column('icon', sa.String(length=255), nullable=False), # PostgreSQL: Keep original syntax
sa.Column('app_id', models.types.StringUUID(), nullable=False), op.create_table('tool_workflow_providers',
sa.Column('user_id', models.types.StringUUID(), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False), sa.Column('name', sa.String(length=40), nullable=False),
sa.Column('description', sa.Text(), nullable=False), sa.Column('icon', sa.String(length=255), nullable=False),
sa.Column('parameter_configuration', sa.Text(), server_default='[]', nullable=False), sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('user_id', models.types.StringUUID(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_workflow_provider_pkey'), sa.Column('description', sa.Text(), nullable=False),
sa.UniqueConstraint('name', 'tenant_id', name='unique_workflow_tool_provider'), sa.Column('parameter_configuration', sa.Text(), server_default='[]', nullable=False),
sa.UniqueConstraint('tenant_id', 'app_id', name='unique_workflow_tool_provider_app_id') sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
) sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_workflow_provider_pkey'),
sa.UniqueConstraint('name', 'tenant_id', name='unique_workflow_tool_provider'),
sa.UniqueConstraint('tenant_id', 'app_id', name='unique_workflow_tool_provider_app_id')
)
else:
# MySQL: Use compatible syntax
op.create_table('tool_workflow_providers',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('name', sa.String(length=40), nullable=False),
sa.Column('icon', sa.String(length=255), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('user_id', models.types.StringUUID(), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('description', models.types.LongText(), nullable=False),
sa.Column('parameter_configuration', models.types.LongText(), default='[]', nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_workflow_provider_pkey'),
sa.UniqueConstraint('name', 'tenant_id', name='unique_workflow_tool_provider'),
sa.UniqueConstraint('tenant_id', 'app_id', name='unique_workflow_tool_provider_app_id')
)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,8 +7,15 @@ Create Date: 2023-07-10 10:26:50.074515
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '7ce5a52e4eee' revision = '7ce5a52e4eee'
down_revision = '2beac44e5f5f' down_revision = '2beac44e5f5f'
@ -18,19 +25,40 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('tool_providers', conn = op.get_bind()
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', postgresql.UUID(), nullable=False), if _is_pg(conn):
sa.Column('tool_name', sa.String(length=40), nullable=False), # PostgreSQL: Keep original syntax
sa.Column('encrypted_credentials', sa.Text(), nullable=True), op.create_table('tool_providers',
sa.Column('is_enabled', sa.Boolean(), server_default=sa.text('false'), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('tool_name', sa.String(length=40), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_provider_pkey'), sa.Column('encrypted_credentials', sa.Text(), nullable=True),
sa.UniqueConstraint('tenant_id', 'tool_name', name='unique_tool_provider_tool_name') sa.Column('is_enabled', sa.Boolean(), server_default=sa.text('false'), nullable=False),
) sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
with op.batch_alter_table('app_model_configs', schema=None) as batch_op: sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
batch_op.add_column(sa.Column('sensitive_word_avoidance', sa.Text(), nullable=True)) sa.PrimaryKeyConstraint('id', name='tool_provider_pkey'),
sa.UniqueConstraint('tenant_id', 'tool_name', name='unique_tool_provider_tool_name')
)
else:
# MySQL: Use compatible syntax
op.create_table('tool_providers',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('tool_name', sa.String(length=40), nullable=False),
sa.Column('encrypted_credentials', models.types.LongText(), nullable=True),
sa.Column('is_enabled', sa.Boolean(), server_default=sa.text('false'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_provider_pkey'),
sa.UniqueConstraint('tenant_id', 'tool_name', name='unique_tool_provider_tool_name')
)
if _is_pg(conn):
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('sensitive_word_avoidance', sa.Text(), nullable=True))
else:
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('sensitive_word_avoidance', models.types.LongText(), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,9 +7,14 @@ Create Date: 2024-06-25 03:20:46.012193
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
import models.types import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '7e6a8693e07a' revision = '7e6a8693e07a'
down_revision = 'b2602e131636' down_revision = 'b2602e131636'
@ -19,14 +24,27 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('dataset_permissions', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('dataset_id', models.types.StringUUID(), nullable=False), if _is_pg(conn):
sa.Column('account_id', models.types.StringUUID(), nullable=False), op.create_table('dataset_permissions',
sa.Column('has_permission', sa.Boolean(), server_default=sa.text('true'), nullable=False), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('dataset_id', models.types.StringUUID(), nullable=False),
sa.PrimaryKeyConstraint('id', name='dataset_permission_pkey') sa.Column('account_id', models.types.StringUUID(), nullable=False),
) sa.Column('has_permission', sa.Boolean(), server_default=sa.text('true'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='dataset_permission_pkey')
)
else:
op.create_table('dataset_permissions',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('dataset_id', models.types.StringUUID(), nullable=False),
sa.Column('account_id', models.types.StringUUID(), nullable=False),
sa.Column('has_permission', sa.Boolean(), server_default=sa.text('true'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='dataset_permission_pkey')
)
with op.batch_alter_table('dataset_permissions', schema=None) as batch_op: with op.batch_alter_table('dataset_permissions', schema=None) as batch_op:
batch_op.create_index('idx_dataset_permissions_account_id', ['account_id'], unique=False) batch_op.create_index('idx_dataset_permissions_account_id', ['account_id'], unique=False)
batch_op.create_index('idx_dataset_permissions_dataset_id', ['dataset_id'], unique=False) batch_op.create_index('idx_dataset_permissions_dataset_id', ['dataset_id'], unique=False)

View File

@ -8,6 +8,12 @@ Create Date: 2023-12-14 07:36:50.705362
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '88072f0caa04' revision = '88072f0caa04'
down_revision = '246ba09cbbdb' down_revision = '246ba09cbbdb'
@ -17,8 +23,14 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tenants', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('custom_config', sa.Text(), nullable=True))
if _is_pg(conn):
with op.batch_alter_table('tenants', schema=None) as batch_op:
batch_op.add_column(sa.Column('custom_config', sa.Text(), nullable=True))
else:
with op.batch_alter_table('tenants', schema=None) as batch_op:
batch_op.add_column(sa.Column('custom_config', models.types.LongText(), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,6 +8,12 @@ Create Date: 2024-01-21 04:10:23.192853
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '89c7899ca936' revision = '89c7899ca936'
down_revision = '187385f442fc' down_revision = '187385f442fc'
@ -17,21 +23,39 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('sites', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('description',
existing_type=sa.VARCHAR(length=255), if _is_pg(conn):
type_=sa.Text(), with op.batch_alter_table('sites', schema=None) as batch_op:
existing_nullable=True) batch_op.alter_column('description',
existing_type=sa.VARCHAR(length=255),
type_=sa.Text(),
existing_nullable=True)
else:
with op.batch_alter_table('sites', schema=None) as batch_op:
batch_op.alter_column('description',
existing_type=sa.VARCHAR(length=255),
type_=models.types.LongText(),
existing_nullable=True)
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('sites', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('description',
existing_type=sa.Text(), if _is_pg(conn):
type_=sa.VARCHAR(length=255), with op.batch_alter_table('sites', schema=None) as batch_op:
existing_nullable=True) batch_op.alter_column('description',
existing_type=sa.Text(),
type_=sa.VARCHAR(length=255),
existing_nullable=True)
else:
with op.batch_alter_table('sites', schema=None) as batch_op:
batch_op.alter_column('description',
existing_type=models.types.LongText(),
type_=sa.VARCHAR(length=255),
existing_nullable=True)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -9,6 +9,12 @@ import sqlalchemy as sa
from alembic import op from alembic import op
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '8d2d099ceb74' revision = '8d2d099ceb74'
down_revision = '7ce5a52e4eee' down_revision = '7ce5a52e4eee'
@ -18,13 +24,24 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('document_segments', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('answer', sa.Text(), nullable=True))
batch_op.add_column(sa.Column('updated_by', postgresql.UUID(), nullable=True)) if _is_pg(conn):
batch_op.add_column(sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False)) with op.batch_alter_table('document_segments', schema=None) as batch_op:
batch_op.add_column(sa.Column('answer', sa.Text(), nullable=True))
batch_op.add_column(sa.Column('updated_by', postgresql.UUID(), nullable=True))
batch_op.add_column(sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False))
with op.batch_alter_table('documents', schema=None) as batch_op: with op.batch_alter_table('documents', schema=None) as batch_op:
batch_op.add_column(sa.Column('doc_form', sa.String(length=255), server_default=sa.text("'text_model'::character varying"), nullable=False)) batch_op.add_column(sa.Column('doc_form', sa.String(length=255), server_default=sa.text("'text_model'::character varying"), nullable=False))
else:
with op.batch_alter_table('document_segments', schema=None) as batch_op:
batch_op.add_column(sa.Column('answer', models.types.LongText(), nullable=True))
batch_op.add_column(sa.Column('updated_by', models.types.StringUUID(), nullable=True))
batch_op.add_column(sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False))
with op.batch_alter_table('documents', schema=None) as batch_op:
batch_op.add_column(sa.Column('doc_form', sa.String(length=255), server_default=sa.text("'text_model'"), nullable=False))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -10,6 +10,10 @@ from alembic import op
import models as models import models as models
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '8e5588e6412e' revision = '8e5588e6412e'
down_revision = '6e957a32015b' down_revision = '6e957a32015b'
@ -19,8 +23,14 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('workflows', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('environment_variables', sa.Text(), server_default='{}', nullable=False))
if _is_pg(conn):
with op.batch_alter_table('workflows', schema=None) as batch_op:
batch_op.add_column(sa.Column('environment_variables', sa.Text(), server_default='{}', nullable=False))
else:
with op.batch_alter_table('workflows', schema=None) as batch_op:
batch_op.add_column(sa.Column('environment_variables', models.types.LongText(), default='{}', nullable=False))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,6 +8,12 @@ Create Date: 2024-01-07 03:57:35.257545
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '8ec536f3c800' revision = '8ec536f3c800'
down_revision = 'ad472b61a054' down_revision = 'ad472b61a054'
@ -17,8 +23,14 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('credentials_str', sa.Text(), nullable=False))
if _is_pg(conn):
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('credentials_str', sa.Text(), nullable=False))
else:
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
batch_op.add_column(sa.Column('credentials_str', models.types.LongText(), nullable=False))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,8 +7,15 @@ Create Date: 2023-11-09 11:39:00.006432
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '8fe468ba0ca5' revision = '8fe468ba0ca5'
down_revision = 'a9836e3baeee' down_revision = 'a9836e3baeee'
@ -18,27 +25,52 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('message_files', conn = op.get_bind()
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('message_id', postgresql.UUID(), nullable=False), if _is_pg(conn):
sa.Column('type', sa.String(length=255), nullable=False), op.create_table('message_files',
sa.Column('transfer_method', sa.String(length=255), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('url', sa.Text(), nullable=True), sa.Column('message_id', postgresql.UUID(), nullable=False),
sa.Column('upload_file_id', postgresql.UUID(), nullable=True), sa.Column('type', sa.String(length=255), nullable=False),
sa.Column('created_by_role', sa.String(length=255), nullable=False), sa.Column('transfer_method', sa.String(length=255), nullable=False),
sa.Column('created_by', postgresql.UUID(), nullable=False), sa.Column('url', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('upload_file_id', postgresql.UUID(), nullable=True),
sa.PrimaryKeyConstraint('id', name='message_file_pkey') sa.Column('created_by_role', sa.String(length=255), nullable=False),
) sa.Column('created_by', postgresql.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='message_file_pkey')
)
else:
op.create_table('message_files',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('message_id', models.types.StringUUID(), nullable=False),
sa.Column('type', sa.String(length=255), nullable=False),
sa.Column('transfer_method', sa.String(length=255), nullable=False),
sa.Column('url', models.types.LongText(), nullable=True),
sa.Column('upload_file_id', models.types.StringUUID(), nullable=True),
sa.Column('created_by_role', sa.String(length=255), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='message_file_pkey')
)
with op.batch_alter_table('message_files', schema=None) as batch_op: with op.batch_alter_table('message_files', schema=None) as batch_op:
batch_op.create_index('message_file_created_by_idx', ['created_by'], unique=False) batch_op.create_index('message_file_created_by_idx', ['created_by'], unique=False)
batch_op.create_index('message_file_message_idx', ['message_id'], unique=False) batch_op.create_index('message_file_message_idx', ['message_id'], unique=False)
with op.batch_alter_table('app_model_configs', schema=None) as batch_op: if _is_pg(conn):
batch_op.add_column(sa.Column('file_upload', sa.Text(), nullable=True)) with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('file_upload', sa.Text(), nullable=True))
else:
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('file_upload', models.types.LongText(), nullable=True))
with op.batch_alter_table('upload_files', schema=None) as batch_op: if _is_pg(conn):
batch_op.add_column(sa.Column('created_by_role', sa.String(length=255), server_default=sa.text("'account'::character varying"), nullable=False)) with op.batch_alter_table('upload_files', schema=None) as batch_op:
batch_op.add_column(sa.Column('created_by_role', sa.String(length=255), server_default=sa.text("'account'::character varying"), nullable=False))
else:
with op.batch_alter_table('upload_files', schema=None) as batch_op:
batch_op.add_column(sa.Column('created_by_role', sa.String(length=255), server_default=sa.text("'account'"), nullable=False))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,8 +7,15 @@ Create Date: 2023-10-27 13:05:58.901858
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '968fff4c0ab9' revision = '968fff4c0ab9'
down_revision = 'b3a09c049e8e' down_revision = 'b3a09c049e8e'
@ -18,16 +25,28 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
op.create_table('api_based_extensions',
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False), if _is_pg(conn):
sa.Column('tenant_id', postgresql.UUID(), nullable=False), op.create_table('api_based_extensions',
sa.Column('name', sa.String(length=255), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('api_endpoint', sa.String(length=255), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=False),
sa.Column('api_key', sa.Text(), nullable=False), sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('api_endpoint', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id', name='api_based_extension_pkey') sa.Column('api_key', sa.Text(), nullable=False),
) sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='api_based_extension_pkey')
)
else:
op.create_table('api_based_extensions',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('api_endpoint', sa.String(length=255), nullable=False),
sa.Column('api_key', models.types.LongText(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='api_based_extension_pkey')
)
with op.batch_alter_table('api_based_extensions', schema=None) as batch_op: with op.batch_alter_table('api_based_extensions', schema=None) as batch_op:
batch_op.create_index('api_based_extension_tenant_idx', ['tenant_id'], unique=False) batch_op.create_index('api_based_extension_tenant_idx', ['tenant_id'], unique=False)

View File

@ -8,6 +8,10 @@ Create Date: 2023-05-17 17:29:01.060435
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '9f4e3427ea84' revision = '9f4e3427ea84'
down_revision = '64b051264f32' down_revision = '64b051264f32'
@ -17,15 +21,30 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('pinned_conversations', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('created_by_role', sa.String(length=255), server_default=sa.text("'end_user'::character varying"), nullable=False))
batch_op.drop_index('pinned_conversation_conversation_idx') if _is_pg(conn):
batch_op.create_index('pinned_conversation_conversation_idx', ['app_id', 'conversation_id', 'created_by_role', 'created_by'], unique=False) # PostgreSQL: Keep original syntax
with op.batch_alter_table('pinned_conversations', schema=None) as batch_op:
batch_op.add_column(sa.Column('created_by_role', sa.String(length=255), server_default=sa.text("'end_user'::character varying"), nullable=False))
batch_op.drop_index('pinned_conversation_conversation_idx')
batch_op.create_index('pinned_conversation_conversation_idx', ['app_id', 'conversation_id', 'created_by_role', 'created_by'], unique=False)
with op.batch_alter_table('saved_messages', schema=None) as batch_op: with op.batch_alter_table('saved_messages', schema=None) as batch_op:
batch_op.add_column(sa.Column('created_by_role', sa.String(length=255), server_default=sa.text("'end_user'::character varying"), nullable=False)) batch_op.add_column(sa.Column('created_by_role', sa.String(length=255), server_default=sa.text("'end_user'::character varying"), nullable=False))
batch_op.drop_index('saved_message_message_idx') batch_op.drop_index('saved_message_message_idx')
batch_op.create_index('saved_message_message_idx', ['app_id', 'message_id', 'created_by_role', 'created_by'], unique=False) batch_op.create_index('saved_message_message_idx', ['app_id', 'message_id', 'created_by_role', 'created_by'], unique=False)
else:
# MySQL: Use compatible syntax
with op.batch_alter_table('pinned_conversations', schema=None) as batch_op:
batch_op.add_column(sa.Column('created_by_role', sa.String(length=255), server_default=sa.text("'end_user'"), nullable=False))
batch_op.drop_index('pinned_conversation_conversation_idx')
batch_op.create_index('pinned_conversation_conversation_idx', ['app_id', 'conversation_id', 'created_by_role', 'created_by'], unique=False)
with op.batch_alter_table('saved_messages', schema=None) as batch_op:
batch_op.add_column(sa.Column('created_by_role', sa.String(length=255), server_default=sa.text("'end_user'"), nullable=False))
batch_op.drop_index('saved_message_message_idx')
batch_op.create_index('saved_message_message_idx', ['app_id', 'message_id', 'created_by_role', 'created_by'], unique=False)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,6 +8,10 @@ Create Date: 2023-05-25 17:50:32.052335
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'a45f4dfde53b' revision = 'a45f4dfde53b'
down_revision = '9f4e3427ea84' down_revision = '9f4e3427ea84'
@ -17,10 +21,18 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('recommended_apps', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('language', sa.String(length=255), server_default=sa.text("'en-US'::character varying"), nullable=False))
batch_op.drop_index('recommended_app_is_listed_idx') if _is_pg(conn):
batch_op.create_index('recommended_app_is_listed_idx', ['is_listed', 'language'], unique=False) with op.batch_alter_table('recommended_apps', schema=None) as batch_op:
batch_op.add_column(sa.Column('language', sa.String(length=255), server_default=sa.text("'en-US'::character varying"), nullable=False))
batch_op.drop_index('recommended_app_is_listed_idx')
batch_op.create_index('recommended_app_is_listed_idx', ['is_listed', 'language'], unique=False)
else:
with op.batch_alter_table('recommended_apps', schema=None) as batch_op:
batch_op.add_column(sa.Column('language', sa.String(length=255), server_default=sa.text("'en-US'"), nullable=False))
batch_op.drop_index('recommended_app_is_listed_idx')
batch_op.create_index('recommended_app_is_listed_idx', ['is_listed', 'language'], unique=False)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,6 +8,12 @@ Create Date: 2023-07-06 17:55:20.894149
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'a5b56fb053ef' revision = 'a5b56fb053ef'
down_revision = 'd3d503a3471c' down_revision = 'd3d503a3471c'
@ -17,8 +23,14 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('app_model_configs', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('speech_to_text', sa.Text(), nullable=True))
if _is_pg(conn):
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('speech_to_text', sa.Text(), nullable=True))
else:
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('speech_to_text', models.types.LongText(), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,6 +8,10 @@ Create Date: 2024-04-02 12:17:22.641525
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'a8d7385a7b66' revision = 'a8d7385a7b66'
down_revision = '17b5ab037c40' down_revision = '17b5ab037c40'
@ -17,10 +21,18 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('embeddings', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('provider_name', sa.String(length=40), server_default=sa.text("''::character varying"), nullable=False))
batch_op.drop_constraint('embedding_hash_idx', type_='unique') if _is_pg(conn):
batch_op.create_unique_constraint('embedding_hash_idx', ['model_name', 'hash', 'provider_name']) with op.batch_alter_table('embeddings', schema=None) as batch_op:
batch_op.add_column(sa.Column('provider_name', sa.String(length=40), server_default=sa.text("''::character varying"), nullable=False))
batch_op.drop_constraint('embedding_hash_idx', type_='unique')
batch_op.create_unique_constraint('embedding_hash_idx', ['model_name', 'hash', 'provider_name'])
else:
with op.batch_alter_table('embeddings', schema=None) as batch_op:
batch_op.add_column(sa.Column('provider_name', sa.String(length=40), server_default=sa.text("''"), nullable=False))
batch_op.drop_constraint('embedding_hash_idx', type_='unique')
batch_op.create_unique_constraint('embedding_hash_idx', ['model_name', 'hash', 'provider_name'])
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,6 +8,12 @@ Create Date: 2023-11-02 04:04:57.609485
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'a9836e3baeee' revision = 'a9836e3baeee'
down_revision = '968fff4c0ab9' down_revision = '968fff4c0ab9'
@ -17,8 +23,14 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('app_model_configs', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('external_data_tools', sa.Text(), nullable=True))
if _is_pg(conn):
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('external_data_tools', sa.Text(), nullable=True))
else:
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('external_data_tools', models.types.LongText(), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,6 +8,12 @@ Create Date: 2024-01-17 01:31:12.670556
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'b24be59fbb04' revision = 'b24be59fbb04'
down_revision = 'de95f5c77138' down_revision = 'de95f5c77138'
@ -17,8 +23,14 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('app_model_configs', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('text_to_speech', sa.Text(), nullable=True))
if _is_pg(conn):
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('text_to_speech', sa.Text(), nullable=True))
else:
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('text_to_speech', models.types.LongText(), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,8 +7,15 @@ Create Date: 2024-02-19 12:47:24.646954
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'b289e2408ee2' revision = 'b289e2408ee2'
down_revision = 'a8d7385a7b66' down_revision = 'a8d7385a7b66'
@ -18,98 +25,190 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('workflow_app_logs', conn = op.get_bind()
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', postgresql.UUID(), nullable=False), if _is_pg(conn):
sa.Column('app_id', postgresql.UUID(), nullable=False), op.create_table('workflow_app_logs',
sa.Column('workflow_id', postgresql.UUID(), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('workflow_run_id', postgresql.UUID(), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=False),
sa.Column('created_from', sa.String(length=255), nullable=False), sa.Column('app_id', postgresql.UUID(), nullable=False),
sa.Column('created_by_role', sa.String(length=255), nullable=False), sa.Column('workflow_id', postgresql.UUID(), nullable=False),
sa.Column('created_by', postgresql.UUID(), nullable=False), sa.Column('workflow_run_id', postgresql.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('created_from', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id', name='workflow_app_log_pkey') sa.Column('created_by_role', sa.String(length=255), nullable=False),
) sa.Column('created_by', postgresql.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='workflow_app_log_pkey')
)
else:
op.create_table('workflow_app_logs',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('workflow_id', models.types.StringUUID(), nullable=False),
sa.Column('workflow_run_id', models.types.StringUUID(), nullable=False),
sa.Column('created_from', sa.String(length=255), nullable=False),
sa.Column('created_by_role', sa.String(length=255), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='workflow_app_log_pkey')
)
with op.batch_alter_table('workflow_app_logs', schema=None) as batch_op: with op.batch_alter_table('workflow_app_logs', schema=None) as batch_op:
batch_op.create_index('workflow_app_log_app_idx', ['tenant_id', 'app_id'], unique=False) batch_op.create_index('workflow_app_log_app_idx', ['tenant_id', 'app_id'], unique=False)
op.create_table('workflow_node_executions', if _is_pg(conn):
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False), op.create_table('workflow_node_executions',
sa.Column('tenant_id', postgresql.UUID(), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('app_id', postgresql.UUID(), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=False),
sa.Column('workflow_id', postgresql.UUID(), nullable=False), sa.Column('app_id', postgresql.UUID(), nullable=False),
sa.Column('triggered_from', sa.String(length=255), nullable=False), sa.Column('workflow_id', postgresql.UUID(), nullable=False),
sa.Column('workflow_run_id', postgresql.UUID(), nullable=True), sa.Column('triggered_from', sa.String(length=255), nullable=False),
sa.Column('index', sa.Integer(), nullable=False), sa.Column('workflow_run_id', postgresql.UUID(), nullable=True),
sa.Column('predecessor_node_id', sa.String(length=255), nullable=True), sa.Column('index', sa.Integer(), nullable=False),
sa.Column('node_id', sa.String(length=255), nullable=False), sa.Column('predecessor_node_id', sa.String(length=255), nullable=True),
sa.Column('node_type', sa.String(length=255), nullable=False), sa.Column('node_id', sa.String(length=255), nullable=False),
sa.Column('title', sa.String(length=255), nullable=False), sa.Column('node_type', sa.String(length=255), nullable=False),
sa.Column('inputs', sa.Text(), nullable=True), sa.Column('title', sa.String(length=255), nullable=False),
sa.Column('process_data', sa.Text(), nullable=True), sa.Column('inputs', sa.Text(), nullable=True),
sa.Column('outputs', sa.Text(), nullable=True), sa.Column('process_data', sa.Text(), nullable=True),
sa.Column('status', sa.String(length=255), nullable=False), sa.Column('outputs', sa.Text(), nullable=True),
sa.Column('error', sa.Text(), nullable=True), sa.Column('status', sa.String(length=255), nullable=False),
sa.Column('elapsed_time', sa.Float(), server_default=sa.text('0'), nullable=False), sa.Column('error', sa.Text(), nullable=True),
sa.Column('execution_metadata', sa.Text(), nullable=True), sa.Column('elapsed_time', sa.Float(), server_default=sa.text('0'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('execution_metadata', sa.Text(), nullable=True),
sa.Column('created_by_role', sa.String(length=255), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('created_by', postgresql.UUID(), nullable=False), sa.Column('created_by_role', sa.String(length=255), nullable=False),
sa.Column('finished_at', sa.DateTime(), nullable=True), sa.Column('created_by', postgresql.UUID(), nullable=False),
sa.PrimaryKeyConstraint('id', name='workflow_node_execution_pkey') sa.Column('finished_at', sa.DateTime(), nullable=True),
) sa.PrimaryKeyConstraint('id', name='workflow_node_execution_pkey')
)
else:
op.create_table('workflow_node_executions',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('workflow_id', models.types.StringUUID(), nullable=False),
sa.Column('triggered_from', sa.String(length=255), nullable=False),
sa.Column('workflow_run_id', models.types.StringUUID(), nullable=True),
sa.Column('index', sa.Integer(), nullable=False),
sa.Column('predecessor_node_id', sa.String(length=255), nullable=True),
sa.Column('node_id', sa.String(length=255), nullable=False),
sa.Column('node_type', sa.String(length=255), nullable=False),
sa.Column('title', sa.String(length=255), nullable=False),
sa.Column('inputs', models.types.LongText(), nullable=True),
sa.Column('process_data', models.types.LongText(), nullable=True),
sa.Column('outputs', models.types.LongText(), nullable=True),
sa.Column('status', sa.String(length=255), nullable=False),
sa.Column('error', models.types.LongText(), nullable=True),
sa.Column('elapsed_time', sa.Float(), server_default=sa.text('0'), nullable=False),
sa.Column('execution_metadata', models.types.LongText(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('created_by_role', sa.String(length=255), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('finished_at', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id', name='workflow_node_execution_pkey')
)
with op.batch_alter_table('workflow_node_executions', schema=None) as batch_op: with op.batch_alter_table('workflow_node_executions', schema=None) as batch_op:
batch_op.create_index('workflow_node_execution_node_run_idx', ['tenant_id', 'app_id', 'workflow_id', 'triggered_from', 'node_id'], unique=False) batch_op.create_index('workflow_node_execution_node_run_idx', ['tenant_id', 'app_id', 'workflow_id', 'triggered_from', 'node_id'], unique=False)
batch_op.create_index('workflow_node_execution_workflow_run_idx', ['tenant_id', 'app_id', 'workflow_id', 'triggered_from', 'workflow_run_id'], unique=False) batch_op.create_index('workflow_node_execution_workflow_run_idx', ['tenant_id', 'app_id', 'workflow_id', 'triggered_from', 'workflow_run_id'], unique=False)
op.create_table('workflow_runs', if _is_pg(conn):
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False), op.create_table('workflow_runs',
sa.Column('tenant_id', postgresql.UUID(), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('app_id', postgresql.UUID(), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=False),
sa.Column('sequence_number', sa.Integer(), nullable=False), sa.Column('app_id', postgresql.UUID(), nullable=False),
sa.Column('workflow_id', postgresql.UUID(), nullable=False), sa.Column('sequence_number', sa.Integer(), nullable=False),
sa.Column('type', sa.String(length=255), nullable=False), sa.Column('workflow_id', postgresql.UUID(), nullable=False),
sa.Column('triggered_from', sa.String(length=255), nullable=False), sa.Column('type', sa.String(length=255), nullable=False),
sa.Column('version', sa.String(length=255), nullable=False), sa.Column('triggered_from', sa.String(length=255), nullable=False),
sa.Column('graph', sa.Text(), nullable=True), sa.Column('version', sa.String(length=255), nullable=False),
sa.Column('inputs', sa.Text(), nullable=True), sa.Column('graph', sa.Text(), nullable=True),
sa.Column('status', sa.String(length=255), nullable=False), sa.Column('inputs', sa.Text(), nullable=True),
sa.Column('outputs', sa.Text(), nullable=True), sa.Column('status', sa.String(length=255), nullable=False),
sa.Column('error', sa.Text(), nullable=True), sa.Column('outputs', sa.Text(), nullable=True),
sa.Column('elapsed_time', sa.Float(), server_default=sa.text('0'), nullable=False), sa.Column('error', sa.Text(), nullable=True),
sa.Column('total_tokens', sa.Integer(), server_default=sa.text('0'), nullable=False), sa.Column('elapsed_time', sa.Float(), server_default=sa.text('0'), nullable=False),
sa.Column('total_steps', sa.Integer(), server_default=sa.text('0'), nullable=True), sa.Column('total_tokens', sa.Integer(), server_default=sa.text('0'), nullable=False),
sa.Column('created_by_role', sa.String(length=255), nullable=False), sa.Column('total_steps', sa.Integer(), server_default=sa.text('0'), nullable=True),
sa.Column('created_by', postgresql.UUID(), nullable=False), sa.Column('created_by_role', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('created_by', postgresql.UUID(), nullable=False),
sa.Column('finished_at', sa.DateTime(), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='workflow_run_pkey') sa.Column('finished_at', sa.DateTime(), nullable=True),
) sa.PrimaryKeyConstraint('id', name='workflow_run_pkey')
)
else:
op.create_table('workflow_runs',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('sequence_number', sa.Integer(), nullable=False),
sa.Column('workflow_id', models.types.StringUUID(), nullable=False),
sa.Column('type', sa.String(length=255), nullable=False),
sa.Column('triggered_from', sa.String(length=255), nullable=False),
sa.Column('version', sa.String(length=255), nullable=False),
sa.Column('graph', models.types.LongText(), nullable=True),
sa.Column('inputs', models.types.LongText(), nullable=True),
sa.Column('status', sa.String(length=255), nullable=False),
sa.Column('outputs', models.types.LongText(), nullable=True),
sa.Column('error', models.types.LongText(), nullable=True),
sa.Column('elapsed_time', sa.Float(), server_default=sa.text('0'), nullable=False),
sa.Column('total_tokens', sa.Integer(), server_default=sa.text('0'), nullable=False),
sa.Column('total_steps', sa.Integer(), server_default=sa.text('0'), nullable=True),
sa.Column('created_by_role', sa.String(length=255), nullable=False),
sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('finished_at', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id', name='workflow_run_pkey')
)
with op.batch_alter_table('workflow_runs', schema=None) as batch_op: with op.batch_alter_table('workflow_runs', schema=None) as batch_op:
batch_op.create_index('workflow_run_triggerd_from_idx', ['tenant_id', 'app_id', 'triggered_from'], unique=False) batch_op.create_index('workflow_run_triggerd_from_idx', ['tenant_id', 'app_id', 'triggered_from'], unique=False)
op.create_table('workflows', if _is_pg(conn):
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False), op.create_table('workflows',
sa.Column('tenant_id', postgresql.UUID(), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('app_id', postgresql.UUID(), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=False),
sa.Column('type', sa.String(length=255), nullable=False), sa.Column('app_id', postgresql.UUID(), nullable=False),
sa.Column('version', sa.String(length=255), nullable=False), sa.Column('type', sa.String(length=255), nullable=False),
sa.Column('graph', sa.Text(), nullable=True), sa.Column('version', sa.String(length=255), nullable=False),
sa.Column('features', sa.Text(), nullable=True), sa.Column('graph', sa.Text(), nullable=True),
sa.Column('created_by', postgresql.UUID(), nullable=False), sa.Column('features', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('created_by', postgresql.UUID(), nullable=False),
sa.Column('updated_by', postgresql.UUID(), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True), sa.Column('updated_by', postgresql.UUID(), nullable=True),
sa.PrimaryKeyConstraint('id', name='workflow_pkey') sa.Column('updated_at', sa.DateTime(), nullable=True),
) sa.PrimaryKeyConstraint('id', name='workflow_pkey')
)
else:
op.create_table('workflows',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('type', sa.String(length=255), nullable=False),
sa.Column('version', sa.String(length=255), nullable=False),
sa.Column('graph', models.types.LongText(), nullable=True),
sa.Column('features', models.types.LongText(), nullable=True),
sa.Column('created_by', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_by', models.types.StringUUID(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id', name='workflow_pkey')
)
with op.batch_alter_table('workflows', schema=None) as batch_op: with op.batch_alter_table('workflows', schema=None) as batch_op:
batch_op.create_index('workflow_version_idx', ['tenant_id', 'app_id', 'version'], unique=False) batch_op.create_index('workflow_version_idx', ['tenant_id', 'app_id', 'version'], unique=False)
with op.batch_alter_table('apps', schema=None) as batch_op: if _is_pg(conn):
batch_op.add_column(sa.Column('workflow_id', postgresql.UUID(), nullable=True)) with op.batch_alter_table('apps', schema=None) as batch_op:
batch_op.add_column(sa.Column('workflow_id', postgresql.UUID(), nullable=True))
with op.batch_alter_table('messages', schema=None) as batch_op: with op.batch_alter_table('messages', schema=None) as batch_op:
batch_op.add_column(sa.Column('workflow_run_id', postgresql.UUID(), nullable=True)) batch_op.add_column(sa.Column('workflow_run_id', postgresql.UUID(), nullable=True))
else:
with op.batch_alter_table('apps', schema=None) as batch_op:
batch_op.add_column(sa.Column('workflow_id', models.types.StringUUID(), nullable=True))
with op.batch_alter_table('messages', schema=None) as batch_op:
batch_op.add_column(sa.Column('workflow_run_id', models.types.StringUUID(), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -8,6 +8,12 @@ Create Date: 2023-10-10 15:23:23.395420
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'b3a09c049e8e' revision = 'b3a09c049e8e'
down_revision = '2e9819ca5b28' down_revision = '2e9819ca5b28'
@ -17,11 +23,20 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('app_model_configs', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('prompt_type', sa.String(length=255), nullable=False, server_default='simple'))
batch_op.add_column(sa.Column('chat_prompt_config', sa.Text(), nullable=True)) if _is_pg(conn):
batch_op.add_column(sa.Column('completion_prompt_config', sa.Text(), nullable=True)) with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('dataset_configs', sa.Text(), nullable=True)) batch_op.add_column(sa.Column('prompt_type', sa.String(length=255), nullable=False, server_default='simple'))
batch_op.add_column(sa.Column('chat_prompt_config', sa.Text(), nullable=True))
batch_op.add_column(sa.Column('completion_prompt_config', sa.Text(), nullable=True))
batch_op.add_column(sa.Column('dataset_configs', sa.Text(), nullable=True))
else:
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('prompt_type', sa.String(length=255), nullable=False, server_default='simple'))
batch_op.add_column(sa.Column('chat_prompt_config', models.types.LongText(), nullable=True))
batch_op.add_column(sa.Column('completion_prompt_config', models.types.LongText(), nullable=True))
batch_op.add_column(sa.Column('dataset_configs', models.types.LongText(), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,8 +7,15 @@ Create Date: 2023-08-10 00:03:44.273430
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'bf0aec5ba2cf' revision = 'bf0aec5ba2cf'
down_revision = 'e35ed59becda' down_revision = 'e35ed59becda'
@ -18,25 +25,48 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('provider_orders', conn = op.get_bind()
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', postgresql.UUID(), nullable=False), if _is_pg(conn):
sa.Column('provider_name', sa.String(length=40), nullable=False), op.create_table('provider_orders',
sa.Column('account_id', postgresql.UUID(), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('payment_product_id', sa.String(length=191), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=False),
sa.Column('payment_id', sa.String(length=191), nullable=True), sa.Column('provider_name', sa.String(length=40), nullable=False),
sa.Column('transaction_id', sa.String(length=191), nullable=True), sa.Column('account_id', postgresql.UUID(), nullable=False),
sa.Column('quantity', sa.Integer(), server_default=sa.text('1'), nullable=False), sa.Column('payment_product_id', sa.String(length=191), nullable=False),
sa.Column('currency', sa.String(length=40), nullable=True), sa.Column('payment_id', sa.String(length=191), nullable=True),
sa.Column('total_amount', sa.Integer(), nullable=True), sa.Column('transaction_id', sa.String(length=191), nullable=True),
sa.Column('payment_status', sa.String(length=40), server_default=sa.text("'wait_pay'::character varying"), nullable=False), sa.Column('quantity', sa.Integer(), server_default=sa.text('1'), nullable=False),
sa.Column('paid_at', sa.DateTime(), nullable=True), sa.Column('currency', sa.String(length=40), nullable=True),
sa.Column('pay_failed_at', sa.DateTime(), nullable=True), sa.Column('total_amount', sa.Integer(), nullable=True),
sa.Column('refunded_at', sa.DateTime(), nullable=True), sa.Column('payment_status', sa.String(length=40), server_default=sa.text("'wait_pay'::character varying"), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('paid_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('pay_failed_at', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id', name='provider_order_pkey') sa.Column('refunded_at', sa.DateTime(), nullable=True),
) sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='provider_order_pkey')
)
else:
op.create_table('provider_orders',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('provider_name', sa.String(length=40), nullable=False),
sa.Column('account_id', models.types.StringUUID(), nullable=False),
sa.Column('payment_product_id', sa.String(length=191), nullable=False),
sa.Column('payment_id', sa.String(length=191), nullable=True),
sa.Column('transaction_id', sa.String(length=191), nullable=True),
sa.Column('quantity', sa.Integer(), server_default=sa.text('1'), nullable=False),
sa.Column('currency', sa.String(length=40), nullable=True),
sa.Column('total_amount', sa.Integer(), nullable=True),
sa.Column('payment_status', sa.String(length=40), server_default=sa.text("'wait_pay'"), nullable=False),
sa.Column('paid_at', sa.DateTime(), nullable=True),
sa.Column('pay_failed_at', sa.DateTime(), nullable=True),
sa.Column('refunded_at', sa.DateTime(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='provider_order_pkey')
)
with op.batch_alter_table('provider_orders', schema=None) as batch_op: with op.batch_alter_table('provider_orders', schema=None) as batch_op:
batch_op.create_index('provider_order_tenant_provider_idx', ['tenant_id', 'provider_name'], unique=False) batch_op.create_index('provider_order_tenant_provider_idx', ['tenant_id', 'provider_name'], unique=False)

View File

@ -8,9 +8,14 @@ Create Date: 2024-06-17 10:01:00.255189
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
from uuid import uuid4
import models.types import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'c031d46af369' revision = 'c031d46af369'
down_revision = '04c602f5dc9b' down_revision = '04c602f5dc9b'
@ -20,16 +25,30 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('trace_app_config', conn = op.get_bind()
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False), if _is_pg(conn):
sa.Column('tracing_provider', sa.String(length=255), nullable=True), op.create_table('trace_app_config',
sa.Column('tracing_config', sa.JSON(), nullable=True), sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.Column('tracing_provider', sa.String(length=255), nullable=True),
sa.Column('is_active', sa.Boolean(), server_default=sa.text('true'), nullable=False), sa.Column('tracing_config', sa.JSON(), nullable=True),
sa.PrimaryKeyConstraint('id', name='trace_app_config_pkey') sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
) sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('is_active', sa.Boolean(), server_default=sa.text('true'), nullable=False),
sa.PrimaryKeyConstraint('id', name='trace_app_config_pkey')
)
else:
op.create_table('trace_app_config',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('tracing_provider', sa.String(length=255), nullable=True),
sa.Column('tracing_config', sa.JSON(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.now(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.now(), nullable=False),
sa.Column('is_active', sa.Boolean(), server_default=sa.text('true'), nullable=False),
sa.PrimaryKeyConstraint('id', name='trace_app_config_pkey')
)
with op.batch_alter_table('trace_app_config', schema=None) as batch_op: with op.batch_alter_table('trace_app_config', schema=None) as batch_op:
batch_op.create_index('trace_app_config_app_id_idx', ['app_id'], unique=False) batch_op.create_index('trace_app_config_app_id_idx', ['app_id'], unique=False)

View File

@ -8,6 +8,12 @@ Create Date: 2024-03-28 11:50:45.364875
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'c3311b089690' revision = 'c3311b089690'
down_revision = 'e2eacc9a1b63' down_revision = 'e2eacc9a1b63'
@ -17,8 +23,14 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('tool_meta_str', sa.Text(), server_default=sa.text("'{}'::text"), nullable=False))
if _is_pg(conn):
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op:
batch_op.add_column(sa.Column('tool_meta_str', sa.Text(), server_default=sa.text("'{}'::text"), nullable=False))
else:
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op:
batch_op.add_column(sa.Column('tool_meta_str', models.types.LongText(), default=sa.text("'{}'"), nullable=False))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,8 +7,15 @@ Create Date: 2024-01-09 11:42:50.664797
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'c71211c8f604' revision = 'c71211c8f604'
down_revision = 'f25003750af4' down_revision = 'f25003750af4'
@ -18,28 +25,54 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('tool_model_invokes', conn = op.get_bind()
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('user_id', postgresql.UUID(), nullable=False), if _is_pg(conn):
sa.Column('tenant_id', postgresql.UUID(), nullable=False), op.create_table('tool_model_invokes',
sa.Column('provider', sa.String(length=40), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tool_type', sa.String(length=40), nullable=False), sa.Column('user_id', postgresql.UUID(), nullable=False),
sa.Column('tool_name', sa.String(length=40), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=False),
sa.Column('tool_id', postgresql.UUID(), nullable=False), sa.Column('provider', sa.String(length=40), nullable=False),
sa.Column('model_parameters', sa.Text(), nullable=False), sa.Column('tool_type', sa.String(length=40), nullable=False),
sa.Column('prompt_messages', sa.Text(), nullable=False), sa.Column('tool_name', sa.String(length=40), nullable=False),
sa.Column('model_response', sa.Text(), nullable=False), sa.Column('tool_id', postgresql.UUID(), nullable=False),
sa.Column('prompt_tokens', sa.Integer(), server_default=sa.text('0'), nullable=False), sa.Column('model_parameters', sa.Text(), nullable=False),
sa.Column('answer_tokens', sa.Integer(), server_default=sa.text('0'), nullable=False), sa.Column('prompt_messages', sa.Text(), nullable=False),
sa.Column('answer_unit_price', sa.Numeric(precision=10, scale=4), nullable=False), sa.Column('model_response', sa.Text(), nullable=False),
sa.Column('answer_price_unit', sa.Numeric(precision=10, scale=7), server_default=sa.text('0.001'), nullable=False), sa.Column('prompt_tokens', sa.Integer(), server_default=sa.text('0'), nullable=False),
sa.Column('provider_response_latency', sa.Float(), server_default=sa.text('0'), nullable=False), sa.Column('answer_tokens', sa.Integer(), server_default=sa.text('0'), nullable=False),
sa.Column('total_price', sa.Numeric(precision=10, scale=7), nullable=True), sa.Column('answer_unit_price', sa.Numeric(precision=10, scale=4), nullable=False),
sa.Column('currency', sa.String(length=255), nullable=False), sa.Column('answer_price_unit', sa.Numeric(precision=10, scale=7), server_default=sa.text('0.001'), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('provider_response_latency', sa.Float(), server_default=sa.text('0'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('total_price', sa.Numeric(precision=10, scale=7), nullable=True),
sa.PrimaryKeyConstraint('id', name='tool_model_invoke_pkey') sa.Column('currency', sa.String(length=255), nullable=False),
) sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_model_invoke_pkey')
)
else:
op.create_table('tool_model_invokes',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('user_id', models.types.StringUUID(), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('provider', sa.String(length=40), nullable=False),
sa.Column('tool_type', sa.String(length=40), nullable=False),
sa.Column('tool_name', sa.String(length=40), nullable=False),
sa.Column('tool_id', models.types.StringUUID(), nullable=False),
sa.Column('model_parameters', models.types.LongText(), nullable=False),
sa.Column('prompt_messages', models.types.LongText(), nullable=False),
sa.Column('model_response', models.types.LongText(), nullable=False),
sa.Column('prompt_tokens', sa.Integer(), server_default=sa.text('0'), nullable=False),
sa.Column('answer_tokens', sa.Integer(), server_default=sa.text('0'), nullable=False),
sa.Column('answer_unit_price', sa.Numeric(precision=10, scale=4), nullable=False),
sa.Column('answer_price_unit', sa.Numeric(precision=10, scale=7), server_default=sa.text('0.001'), nullable=False),
sa.Column('provider_response_latency', sa.Float(), server_default=sa.text('0'), nullable=False),
sa.Column('total_price', sa.Numeric(precision=10, scale=7), nullable=True),
sa.Column('currency', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='tool_model_invoke_pkey')
)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -9,6 +9,10 @@ import sqlalchemy as sa
from alembic import op from alembic import op
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'cc04d0998d4d' revision = 'cc04d0998d4d'
down_revision = 'b289e2408ee2' down_revision = 'b289e2408ee2'
@ -18,16 +22,30 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('app_model_configs', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('provider',
existing_type=sa.VARCHAR(length=255), if _is_pg(conn):
nullable=True) with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.alter_column('model_id', batch_op.alter_column('provider',
existing_type=sa.VARCHAR(length=255), existing_type=sa.VARCHAR(length=255),
nullable=True) nullable=True)
batch_op.alter_column('configs', batch_op.alter_column('model_id',
existing_type=postgresql.JSON(astext_type=sa.Text()), existing_type=sa.VARCHAR(length=255),
nullable=True) nullable=True)
batch_op.alter_column('configs',
existing_type=postgresql.JSON(astext_type=sa.Text()),
nullable=True)
else:
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.alter_column('provider',
existing_type=sa.VARCHAR(length=255),
nullable=True)
batch_op.alter_column('model_id',
existing_type=sa.VARCHAR(length=255),
nullable=True)
batch_op.alter_column('configs',
existing_type=sa.JSON(),
nullable=True)
with op.batch_alter_table('apps', schema=None) as batch_op: with op.batch_alter_table('apps', schema=None) as batch_op:
batch_op.alter_column('api_rpm', batch_op.alter_column('api_rpm',
@ -45,6 +63,8 @@ def upgrade():
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
with op.batch_alter_table('apps', schema=None) as batch_op: with op.batch_alter_table('apps', schema=None) as batch_op:
batch_op.alter_column('api_rpm', batch_op.alter_column('api_rpm',
existing_type=sa.Integer(), existing_type=sa.Integer(),
@ -56,15 +76,27 @@ def downgrade():
server_default=None, server_default=None,
nullable=False) nullable=False)
with op.batch_alter_table('app_model_configs', schema=None) as batch_op: if _is_pg(conn):
batch_op.alter_column('configs', with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
existing_type=postgresql.JSON(astext_type=sa.Text()), batch_op.alter_column('configs',
nullable=False) existing_type=postgresql.JSON(astext_type=sa.Text()),
batch_op.alter_column('model_id', nullable=False)
existing_type=sa.VARCHAR(length=255), batch_op.alter_column('model_id',
nullable=False) existing_type=sa.VARCHAR(length=255),
batch_op.alter_column('provider', nullable=False)
existing_type=sa.VARCHAR(length=255), batch_op.alter_column('provider',
nullable=False) existing_type=sa.VARCHAR(length=255),
nullable=False)
else:
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.alter_column('configs',
existing_type=sa.JSON(),
nullable=False)
batch_op.alter_column('model_id',
existing_type=sa.VARCHAR(length=255),
nullable=False)
batch_op.alter_column('provider',
existing_type=sa.VARCHAR(length=255),
nullable=False)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,8 +7,15 @@ Create Date: 2023-12-12 06:58:41.054544
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'e1901f623fd0' revision = 'e1901f623fd0'
down_revision = 'fca025d3b60f' down_revision = 'fca025d3b60f'
@ -18,51 +25,98 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('app_annotation_hit_histories', conn = op.get_bind()
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('app_id', postgresql.UUID(), nullable=False), if _is_pg(conn):
sa.Column('annotation_id', postgresql.UUID(), nullable=False), op.create_table('app_annotation_hit_histories',
sa.Column('source', sa.Text(), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('question', sa.Text(), nullable=False), sa.Column('app_id', postgresql.UUID(), nullable=False),
sa.Column('account_id', postgresql.UUID(), nullable=False), sa.Column('annotation_id', postgresql.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('source', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id', name='app_annotation_hit_histories_pkey') sa.Column('question', sa.Text(), nullable=False),
) sa.Column('account_id', postgresql.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='app_annotation_hit_histories_pkey')
)
else:
op.create_table('app_annotation_hit_histories',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('app_id', models.types.StringUUID(), nullable=False),
sa.Column('annotation_id', models.types.StringUUID(), nullable=False),
sa.Column('source', models.types.LongText(), nullable=False),
sa.Column('question', models.types.LongText(), nullable=False),
sa.Column('account_id', models.types.StringUUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.PrimaryKeyConstraint('id', name='app_annotation_hit_histories_pkey')
)
with op.batch_alter_table('app_annotation_hit_histories', schema=None) as batch_op: with op.batch_alter_table('app_annotation_hit_histories', schema=None) as batch_op:
batch_op.create_index('app_annotation_hit_histories_account_idx', ['account_id'], unique=False) batch_op.create_index('app_annotation_hit_histories_account_idx', ['account_id'], unique=False)
batch_op.create_index('app_annotation_hit_histories_annotation_idx', ['annotation_id'], unique=False) batch_op.create_index('app_annotation_hit_histories_annotation_idx', ['annotation_id'], unique=False)
batch_op.create_index('app_annotation_hit_histories_app_idx', ['app_id'], unique=False) batch_op.create_index('app_annotation_hit_histories_app_idx', ['app_id'], unique=False)
with op.batch_alter_table('app_model_configs', schema=None) as batch_op: if _is_pg(conn):
batch_op.add_column(sa.Column('annotation_reply', sa.Text(), nullable=True)) with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('annotation_reply', sa.Text(), nullable=True))
else:
with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
batch_op.add_column(sa.Column('annotation_reply', models.types.LongText(), nullable=True))
with op.batch_alter_table('dataset_collection_bindings', schema=None) as batch_op: if _is_pg(conn):
batch_op.add_column(sa.Column('type', sa.String(length=40), server_default=sa.text("'dataset'::character varying"), nullable=False)) with op.batch_alter_table('dataset_collection_bindings', schema=None) as batch_op:
batch_op.add_column(sa.Column('type', sa.String(length=40), server_default=sa.text("'dataset'::character varying"), nullable=False))
else:
with op.batch_alter_table('dataset_collection_bindings', schema=None) as batch_op:
batch_op.add_column(sa.Column('type', sa.String(length=40), server_default=sa.text("'dataset'"), nullable=False))
with op.batch_alter_table('message_annotations', schema=None) as batch_op: if _is_pg(conn):
batch_op.add_column(sa.Column('question', sa.Text(), nullable=True)) with op.batch_alter_table('message_annotations', schema=None) as batch_op:
batch_op.add_column(sa.Column('hit_count', sa.Integer(), server_default=sa.text('0'), nullable=False)) batch_op.add_column(sa.Column('question', sa.Text(), nullable=True))
batch_op.alter_column('conversation_id', batch_op.add_column(sa.Column('hit_count', sa.Integer(), server_default=sa.text('0'), nullable=False))
existing_type=postgresql.UUID(), batch_op.alter_column('conversation_id',
nullable=True) existing_type=postgresql.UUID(),
batch_op.alter_column('message_id', nullable=True)
existing_type=postgresql.UUID(), batch_op.alter_column('message_id',
nullable=True) existing_type=postgresql.UUID(),
nullable=True)
else:
with op.batch_alter_table('message_annotations', schema=None) as batch_op:
batch_op.add_column(sa.Column('question', models.types.LongText(), nullable=True))
batch_op.add_column(sa.Column('hit_count', sa.Integer(), server_default=sa.text('0'), nullable=False))
batch_op.alter_column('conversation_id',
existing_type=models.types.StringUUID(),
nullable=True)
batch_op.alter_column('message_id',
existing_type=models.types.StringUUID(),
nullable=True)
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('message_annotations', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('message_id',
existing_type=postgresql.UUID(), if _is_pg(conn):
nullable=False) with op.batch_alter_table('message_annotations', schema=None) as batch_op:
batch_op.alter_column('conversation_id', batch_op.alter_column('message_id',
existing_type=postgresql.UUID(), existing_type=postgresql.UUID(),
nullable=False) nullable=False)
batch_op.drop_column('hit_count') batch_op.alter_column('conversation_id',
batch_op.drop_column('question') existing_type=postgresql.UUID(),
nullable=False)
batch_op.drop_column('hit_count')
batch_op.drop_column('question')
else:
with op.batch_alter_table('message_annotations', schema=None) as batch_op:
batch_op.alter_column('message_id',
existing_type=models.types.StringUUID(),
nullable=False)
batch_op.alter_column('conversation_id',
existing_type=models.types.StringUUID(),
nullable=False)
batch_op.drop_column('hit_count')
batch_op.drop_column('question')
with op.batch_alter_table('dataset_collection_bindings', schema=None) as batch_op: with op.batch_alter_table('dataset_collection_bindings', schema=None) as batch_op:
batch_op.drop_column('type') batch_op.drop_column('type')

View File

@ -8,6 +8,12 @@ Create Date: 2024-03-21 09:31:27.342221
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'e2eacc9a1b63' revision = 'e2eacc9a1b63'
down_revision = '563cf8bf777b' down_revision = '563cf8bf777b'
@ -17,14 +23,23 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
with op.batch_alter_table('conversations', schema=None) as batch_op: with op.batch_alter_table('conversations', schema=None) as batch_op:
batch_op.add_column(sa.Column('invoke_from', sa.String(length=255), nullable=True)) batch_op.add_column(sa.Column('invoke_from', sa.String(length=255), nullable=True))
with op.batch_alter_table('messages', schema=None) as batch_op: if _is_pg(conn):
batch_op.add_column(sa.Column('status', sa.String(length=255), server_default=sa.text("'normal'::character varying"), nullable=False)) with op.batch_alter_table('messages', schema=None) as batch_op:
batch_op.add_column(sa.Column('error', sa.Text(), nullable=True)) batch_op.add_column(sa.Column('status', sa.String(length=255), server_default=sa.text("'normal'::character varying"), nullable=False))
batch_op.add_column(sa.Column('message_metadata', sa.Text(), nullable=True)) batch_op.add_column(sa.Column('error', sa.Text(), nullable=True))
batch_op.add_column(sa.Column('invoke_from', sa.String(length=255), nullable=True)) batch_op.add_column(sa.Column('message_metadata', sa.Text(), nullable=True))
batch_op.add_column(sa.Column('invoke_from', sa.String(length=255), nullable=True))
else:
with op.batch_alter_table('messages', schema=None) as batch_op:
batch_op.add_column(sa.Column('status', sa.String(length=255), server_default=sa.text("'normal'"), nullable=False))
batch_op.add_column(sa.Column('error', models.types.LongText(), nullable=True))
batch_op.add_column(sa.Column('message_metadata', models.types.LongText(), nullable=True))
batch_op.add_column(sa.Column('invoke_from', sa.String(length=255), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -7,8 +7,15 @@ Create Date: 2023-06-06 19:58:33.103819
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from uuid import uuid4
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
import models.types
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'e32f6ccb87c6' revision = 'e32f6ccb87c6'
down_revision = '614f77cecc48' down_revision = '614f77cecc48'
@ -18,28 +25,52 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('data_source_bindings', conn = op.get_bind()
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('tenant_id', postgresql.UUID(), nullable=False), if _is_pg(conn):
sa.Column('access_token', sa.String(length=255), nullable=False), op.create_table('data_source_bindings',
sa.Column('provider', sa.String(length=255), nullable=False), sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('source_info', postgresql.JSONB(astext_type=sa.Text()), nullable=False), sa.Column('tenant_id', postgresql.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('access_token', sa.String(length=255), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), sa.Column('provider', sa.String(length=255), nullable=False),
sa.Column('disabled', sa.Boolean(), server_default=sa.text('false'), nullable=True), sa.Column('source_info', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.PrimaryKeyConstraint('id', name='source_binding_pkey') sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
) sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('disabled', sa.Boolean(), server_default=sa.text('false'), nullable=True),
sa.PrimaryKeyConstraint('id', name='source_binding_pkey')
)
else:
op.create_table('data_source_bindings',
sa.Column('id', models.types.StringUUID(), default=lambda: str(uuid4()), nullable=False),
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
sa.Column('access_token', sa.String(length=255), nullable=False),
sa.Column('provider', sa.String(length=255), nullable=False),
sa.Column('source_info', sa.JSON(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
sa.Column('disabled', sa.Boolean(), server_default=sa.text('false'), nullable=True),
sa.PrimaryKeyConstraint('id', name='source_binding_pkey')
)
with op.batch_alter_table('data_source_bindings', schema=None) as batch_op: with op.batch_alter_table('data_source_bindings', schema=None) as batch_op:
batch_op.create_index('source_binding_tenant_id_idx', ['tenant_id'], unique=False) batch_op.create_index('source_binding_tenant_id_idx', ['tenant_id'], unique=False)
batch_op.create_index('source_info_idx', ['source_info'], unique=False, postgresql_using='gin') if _is_pg(conn):
batch_op.create_index('source_info_idx', ['source_info'], unique=False, postgresql_using='gin')
else:
pass
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
with op.batch_alter_table('data_source_bindings', schema=None) as batch_op: with op.batch_alter_table('data_source_bindings', schema=None) as batch_op:
batch_op.drop_index('source_info_idx', postgresql_using='gin') if _is_pg(conn):
batch_op.drop_index('source_info_idx', postgresql_using='gin')
else:
pass
batch_op.drop_index('source_binding_tenant_id_idx') batch_op.drop_index('source_binding_tenant_id_idx')
op.drop_table('data_source_bindings') op.drop_table('data_source_bindings')

View File

@ -8,6 +8,10 @@ Create Date: 2023-08-15 20:54:58.936787
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'e8883b0148c9' revision = 'e8883b0148c9'
down_revision = '2c8af9671032' down_revision = '2c8af9671032'
@ -17,9 +21,18 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('datasets', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('embedding_model', sa.String(length=255), server_default=sa.text("'text-embedding-ada-002'::character varying"), nullable=False))
batch_op.add_column(sa.Column('embedding_model_provider', sa.String(length=255), server_default=sa.text("'openai'::character varying"), nullable=False)) if _is_pg(conn):
# PostgreSQL: Keep original syntax
with op.batch_alter_table('datasets', schema=None) as batch_op:
batch_op.add_column(sa.Column('embedding_model', sa.String(length=255), server_default=sa.text("'text-embedding-ada-002'::character varying"), nullable=False))
batch_op.add_column(sa.Column('embedding_model_provider', sa.String(length=255), server_default=sa.text("'openai'::character varying"), nullable=False))
else:
# MySQL: Use compatible syntax
with op.batch_alter_table('datasets', schema=None) as batch_op:
batch_op.add_column(sa.Column('embedding_model', sa.String(length=255), server_default=sa.text("'text-embedding-ada-002'"), nullable=False))
batch_op.add_column(sa.Column('embedding_model_provider', sa.String(length=255), server_default=sa.text("'openai'"), nullable=False))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@ -10,6 +10,10 @@ from alembic import op
import models as models import models as models
def _is_pg(conn):
return conn.dialect.name == "postgresql"
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'eeb2e349e6ac' revision = 'eeb2e349e6ac'
down_revision = '53bf8af60645' down_revision = '53bf8af60645'
@ -19,30 +23,50 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
with op.batch_alter_table('dataset_collection_bindings', schema=None) as batch_op: with op.batch_alter_table('dataset_collection_bindings', schema=None) as batch_op:
batch_op.alter_column('model_name', batch_op.alter_column('model_name',
existing_type=sa.VARCHAR(length=40), existing_type=sa.VARCHAR(length=40),
type_=sa.String(length=255), type_=sa.String(length=255),
existing_nullable=False) existing_nullable=False)
with op.batch_alter_table('embeddings', schema=None) as batch_op: if _is_pg(conn):
batch_op.alter_column('model_name', with op.batch_alter_table('embeddings', schema=None) as batch_op:
existing_type=sa.VARCHAR(length=40), batch_op.alter_column('model_name',
type_=sa.String(length=255), existing_type=sa.VARCHAR(length=40),
existing_nullable=False, type_=sa.String(length=255),
existing_server_default=sa.text("'text-embedding-ada-002'::character varying")) existing_nullable=False,
existing_server_default=sa.text("'text-embedding-ada-002'::character varying"))
else:
with op.batch_alter_table('embeddings', schema=None) as batch_op:
batch_op.alter_column('model_name',
existing_type=sa.VARCHAR(length=40),
type_=sa.String(length=255),
existing_nullable=False,
existing_server_default=sa.text("'text-embedding-ada-002'"))
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('embeddings', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('model_name',
existing_type=sa.String(length=255), if _is_pg(conn):
type_=sa.VARCHAR(length=40), with op.batch_alter_table('embeddings', schema=None) as batch_op:
existing_nullable=False, batch_op.alter_column('model_name',
existing_server_default=sa.text("'text-embedding-ada-002'::character varying")) existing_type=sa.String(length=255),
type_=sa.VARCHAR(length=40),
existing_nullable=False,
existing_server_default=sa.text("'text-embedding-ada-002'::character varying"))
else:
with op.batch_alter_table('embeddings', schema=None) as batch_op:
batch_op.alter_column('model_name',
existing_type=sa.String(length=255),
type_=sa.VARCHAR(length=40),
existing_nullable=False,
existing_server_default=sa.text("'text-embedding-ada-002'"))
with op.batch_alter_table('dataset_collection_bindings', schema=None) as batch_op: with op.batch_alter_table('dataset_collection_bindings', schema=None) as batch_op:
batch_op.alter_column('model_name', batch_op.alter_column('model_name',

Some files were not shown because too many files have changed in this diff Show More