-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: join primary key to unique constraint
- Loading branch information
xiaozeyu
committed
Aug 9, 2024
1 parent
633808d
commit 5271612
Showing
8 changed files
with
179 additions
and
17 deletions.
There are no files selected for viewing
155 changes: 155 additions & 0 deletions
155
api/migrations/versions/b889f0fceba0_join_primary_key_to_unique_constraint.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
"""join_primary_key_to_unique_constraint | ||
Revision ID: b889f0fceba0 | ||
Revises: eeb2e349e6ac | ||
Create Date: 2024-08-09 02:07:45.256491 | ||
""" | ||
from alembic import op | ||
import models as models | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'b889f0fceba0' | ||
down_revision = 'eeb2e349e6ac' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('account_integrates', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_account_provider', type_='unique') | ||
batch_op.create_unique_constraint('unique_account_provider', ['account_id', 'provider', 'id']) | ||
batch_op.drop_constraint('unique_provider_open_id', type_='unique') | ||
batch_op.create_unique_constraint('unique_provider_open_id', ['provider', 'open_id', 'id']) | ||
|
||
with op.batch_alter_table('celery_taskmeta', schema=None) as batch_op: | ||
batch_op.drop_constraint('celery_taskmeta_task_id_key', type_='unique') | ||
batch_op.create_unique_constraint('unique_task_id', ['task_id', 'id']) | ||
|
||
with op.batch_alter_table('celery_tasksetmeta', schema=None) as batch_op: | ||
batch_op.drop_constraint('celery_tasksetmeta_taskset_id_key', type_='unique') | ||
batch_op.create_unique_constraint('unique_taskset_id', ['taskset_id', 'id']) | ||
|
||
with op.batch_alter_table('dataset_keyword_tables', schema=None) as batch_op: | ||
batch_op.drop_constraint('dataset_keyword_tables_dataset_id_key', type_='unique') | ||
batch_op.create_unique_constraint('unique_dataset_id', ['dataset_id', 'id']) | ||
|
||
with op.batch_alter_table('embeddings', schema=None) as batch_op: | ||
batch_op.drop_constraint('embedding_hash_idx', type_='unique') | ||
batch_op.create_unique_constraint('embedding_hash_idx', ['model_name', 'hash', 'provider_name', 'id']) | ||
|
||
with op.batch_alter_table('installed_apps', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_tenant_app', type_='unique') | ||
batch_op.create_unique_constraint('unique_tenant_app', ['tenant_id', 'app_id', 'id']) | ||
|
||
with op.batch_alter_table('provider_models', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_provider_model_name', type_='unique') | ||
batch_op.create_unique_constraint('unique_provider_model_name', ['tenant_id', 'provider_name', 'model_name', 'model_type', 'id']) | ||
|
||
with op.batch_alter_table('providers', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_provider_name_type_quota', type_='unique') | ||
batch_op.create_unique_constraint('unique_provider_name_type_quota', ['tenant_id', 'provider_name', 'provider_type', 'quota_type', 'id']) | ||
|
||
with op.batch_alter_table('tenant_account_joins', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_tenant_account_join', type_='unique') | ||
batch_op.create_unique_constraint('unique_tenant_account_join', ['tenant_id', 'account_id', 'id']) | ||
|
||
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_api_tool_provider', type_='unique') | ||
batch_op.create_unique_constraint('unique_api_tool_provider', ['name', 'tenant_id', 'id']) | ||
|
||
with op.batch_alter_table('tool_builtin_providers', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_builtin_tool_provider', type_='unique') | ||
batch_op.create_unique_constraint('unique_builtin_tool_provider', ['tenant_id', 'provider', 'id']) | ||
|
||
with op.batch_alter_table('tool_label_bindings', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_tool_label_bind', type_='unique') | ||
batch_op.create_unique_constraint('unique_tool_label_bind', ['tool_id', 'label_name', 'id']) | ||
|
||
with op.batch_alter_table('tool_providers', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_tool_provider_tool_name', type_='unique') | ||
batch_op.create_unique_constraint('unique_tool_provider_tool_name', ['tenant_id', 'tool_name', 'id']) | ||
|
||
with op.batch_alter_table('tool_published_apps', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_published_app_tool', type_='unique') | ||
batch_op.create_unique_constraint('unique_published_app_tool', ['app_id', 'user_id', 'id']) | ||
|
||
with op.batch_alter_table('tool_workflow_providers', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_workflow_tool_provider', type_='unique') | ||
batch_op.create_unique_constraint('unique_workflow_tool_provider', ['name', 'tenant_id', 'id']) | ||
batch_op.drop_constraint('unique_workflow_tool_provider_app_id', type_='unique') | ||
batch_op.create_unique_constraint('unique_workflow_tool_provider_app_id', ['tenant_id', 'app_id', 'id']) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('tool_workflow_providers', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_workflow_tool_provider_app_id', type_='unique') | ||
batch_op.create_unique_constraint('unique_workflow_tool_provider_app_id', ['tenant_id', 'app_id']) | ||
batch_op.drop_constraint('unique_workflow_tool_provider', type_='unique') | ||
batch_op.create_unique_constraint('unique_workflow_tool_provider', ['name', 'tenant_id']) | ||
|
||
with op.batch_alter_table('tool_published_apps', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_published_app_tool', type_='unique') | ||
batch_op.create_unique_constraint('unique_published_app_tool', ['app_id', 'user_id']) | ||
|
||
with op.batch_alter_table('tool_providers', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_tool_provider_tool_name', type_='unique') | ||
batch_op.create_unique_constraint('unique_tool_provider_tool_name', ['tenant_id', 'tool_name']) | ||
|
||
with op.batch_alter_table('tool_label_bindings', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_tool_label_bind', type_='unique') | ||
batch_op.create_unique_constraint('unique_tool_label_bind', ['tool_id', 'label_name']) | ||
|
||
with op.batch_alter_table('tool_builtin_providers', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_builtin_tool_provider', type_='unique') | ||
batch_op.create_unique_constraint('unique_builtin_tool_provider', ['tenant_id', 'provider']) | ||
|
||
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_api_tool_provider', type_='unique') | ||
batch_op.create_unique_constraint('unique_api_tool_provider', ['name', 'tenant_id']) | ||
|
||
with op.batch_alter_table('tenant_account_joins', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_tenant_account_join', type_='unique') | ||
batch_op.create_unique_constraint('unique_tenant_account_join', ['tenant_id', 'account_id']) | ||
|
||
with op.batch_alter_table('providers', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_provider_name_type_quota', type_='unique') | ||
batch_op.create_unique_constraint('unique_provider_name_type_quota', ['tenant_id', 'provider_name', 'provider_type', 'quota_type']) | ||
|
||
with op.batch_alter_table('provider_models', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_provider_model_name', type_='unique') | ||
batch_op.create_unique_constraint('unique_provider_model_name', ['tenant_id', 'provider_name', 'model_name', 'model_type']) | ||
|
||
with op.batch_alter_table('installed_apps', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_tenant_app', type_='unique') | ||
batch_op.create_unique_constraint('unique_tenant_app', ['tenant_id', 'app_id']) | ||
|
||
with op.batch_alter_table('embeddings', schema=None) as batch_op: | ||
batch_op.drop_constraint('embedding_hash_idx', type_='unique') | ||
batch_op.create_unique_constraint('embedding_hash_idx', ['model_name', 'hash', 'provider_name']) | ||
|
||
with op.batch_alter_table('dataset_keyword_tables', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_dataset_id', type_='unique') | ||
batch_op.create_unique_constraint('dataset_keyword_tables_dataset_id_key', ['dataset_id']) | ||
|
||
with op.batch_alter_table('celery_tasksetmeta', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_taskset_id', type_='unique') | ||
batch_op.create_unique_constraint('celery_tasksetmeta_taskset_id_key', ['taskset_id']) | ||
|
||
with op.batch_alter_table('celery_taskmeta', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_task_id', type_='unique') | ||
batch_op.create_unique_constraint('celery_taskmeta_task_id_key', ['task_id']) | ||
|
||
with op.batch_alter_table('account_integrates', schema=None) as batch_op: | ||
batch_op.drop_constraint('unique_provider_open_id', type_='unique') | ||
batch_op.create_unique_constraint('unique_provider_open_id', ['provider', 'open_id']) | ||
batch_op.drop_constraint('unique_account_provider', type_='unique') | ||
batch_op.create_unique_constraint('unique_account_provider', ['account_id', 'provider']) | ||
|
||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters