From b1ef024724438074e826c5a6df398db47a6fca24 Mon Sep 17 00:00:00 2001 From: ZhenYi <434836402@qq.com> Date: Mon, 11 May 2026 01:31:33 +0800 Subject: [PATCH] fix(migrate): reorder create_project before add_workspace_id_to_project and remove foreign keys - Move create_project migration before add_workspace_id_to_project so the project table exists when workspace_id column is added - Remove all FOREIGN KEY constraints from migration SQL files --- libs/migrate/lib.rs | 4 ++-- .../sql/m20260508_000001_create_ai_conversation.sql | 4 ---- libs/migrate/sql/m20260508_000002_create_ai_message.sql | 8 -------- .../sql/m20260508_000003_create_ai_message_fork.sql | 8 -------- .../m20260508_000004_create_ai_shared_conversation.sql | 4 ---- .../m20260508_000007_create_project_context_setting.sql | 4 ---- 6 files changed, 2 insertions(+), 30 deletions(-) diff --git a/libs/migrate/lib.rs b/libs/migrate/lib.rs index 9abfc75..ac2f610 100644 --- a/libs/migrate/lib.rs +++ b/libs/migrate/lib.rs @@ -77,12 +77,12 @@ impl MigratorTrait for Migrator { // Workspace tables Box::new(m20260411_000001_create_workspace::Migration), Box::new(m20260411_000002_create_workspace_membership::Migration), - Box::new(m20260411_000003_add_workspace_id_to_project::Migration), Box::new(m20260411_000004_add_invite_token_to_workspace_membership::Migration), Box::new(m20260412_000001_create_workspace_billing::Migration), Box::new(m20260412_000002_create_workspace_billing_history::Migration), - // Project tables + // Project tables (must come before add_workspace_id_to_project) Box::new(m20250628_000013_create_project::Migration), + Box::new(m20260411_000003_add_workspace_id_to_project::Migration), Box::new(m20250628_000014_create_project_access_log::Migration), Box::new(m20250628_000015_create_project_audit_log::Migration), Box::new(m20250628_000016_create_project_billing::Migration), diff --git a/libs/migrate/sql/m20260508_000001_create_ai_conversation.sql b/libs/migrate/sql/m20260508_000001_create_ai_conversation.sql index e5623a1..3a4cc40 100644 --- a/libs/migrate/sql/m20260508_000001_create_ai_conversation.sql +++ b/libs/migrate/sql/m20260508_000001_create_ai_conversation.sql @@ -21,7 +21,3 @@ CREATE INDEX IF NOT EXISTS idx_ai_conv_project_id ON ai_conversation (project_id CREATE INDEX IF NOT EXISTS idx_ai_conv_scope ON ai_conversation (scope); CREATE INDEX IF NOT EXISTS idx_ai_conv_user_created ON ai_conversation (user_id, created_at DESC); CREATE INDEX IF NOT EXISTS idx_ai_conv_project_created ON ai_conversation (project_id, created_at DESC); - -ALTER TABLE ai_conversation - ADD CONSTRAINT fk_ai_conv_project - FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE; diff --git a/libs/migrate/sql/m20260508_000002_create_ai_message.sql b/libs/migrate/sql/m20260508_000002_create_ai_message.sql index 0050190..9c49811 100644 --- a/libs/migrate/sql/m20260508_000002_create_ai_message.sql +++ b/libs/migrate/sql/m20260508_000002_create_ai_message.sql @@ -17,11 +17,3 @@ CREATE TABLE IF NOT EXISTS ai_message ( CREATE INDEX IF NOT EXISTS idx_ai_msg_conv ON ai_message (conversation_id, created_at); CREATE INDEX IF NOT EXISTS idx_ai_msg_parent ON ai_message (parent_message_id); - -ALTER TABLE ai_message - ADD CONSTRAINT fk_ai_msg_conv - FOREIGN KEY (conversation_id) REFERENCES ai_conversation(id) ON DELETE CASCADE; - -ALTER TABLE ai_message - ADD CONSTRAINT fk_ai_msg_parent - FOREIGN KEY (parent_message_id) REFERENCES ai_message(id) ON DELETE SET NULL; diff --git a/libs/migrate/sql/m20260508_000003_create_ai_message_fork.sql b/libs/migrate/sql/m20260508_000003_create_ai_message_fork.sql index 27d88b8..f5480e1 100644 --- a/libs/migrate/sql/m20260508_000003_create_ai_message_fork.sql +++ b/libs/migrate/sql/m20260508_000003_create_ai_message_fork.sql @@ -7,11 +7,3 @@ CREATE TABLE IF NOT EXISTS ai_message_fork ( CREATE INDEX IF NOT EXISTS idx_ai_fork_source ON ai_message_fork (source_message_id); CREATE INDEX IF NOT EXISTS idx_ai_fork_fork ON ai_message_fork (fork_message_id); - -ALTER TABLE ai_message_fork - ADD CONSTRAINT fk_ai_fork_source - FOREIGN KEY (source_message_id) REFERENCES ai_message(id) ON DELETE CASCADE; - -ALTER TABLE ai_message_fork - ADD CONSTRAINT fk_ai_fork_fork - FOREIGN KEY (fork_message_id) REFERENCES ai_message(id) ON DELETE CASCADE; diff --git a/libs/migrate/sql/m20260508_000004_create_ai_shared_conversation.sql b/libs/migrate/sql/m20260508_000004_create_ai_shared_conversation.sql index a4e01ac..d861f42 100644 --- a/libs/migrate/sql/m20260508_000004_create_ai_shared_conversation.sql +++ b/libs/migrate/sql/m20260508_000004_create_ai_shared_conversation.sql @@ -10,7 +10,3 @@ CREATE TABLE IF NOT EXISTS ai_shared_conversation ( CREATE INDEX IF NOT EXISTS idx_ai_share_conv ON ai_shared_conversation (conversation_id); CREATE INDEX IF NOT EXISTS idx_ai_share_token ON ai_shared_conversation (share_token); - -ALTER TABLE ai_shared_conversation - ADD CONSTRAINT fk_ai_share_conv - FOREIGN KEY (conversation_id) REFERENCES ai_conversation(id) ON DELETE CASCADE; diff --git a/libs/migrate/sql/m20260508_000007_create_project_context_setting.sql b/libs/migrate/sql/m20260508_000007_create_project_context_setting.sql index 938001d..5d63181 100644 --- a/libs/migrate/sql/m20260508_000007_create_project_context_setting.sql +++ b/libs/migrate/sql/m20260508_000007_create_project_context_setting.sql @@ -12,7 +12,3 @@ CREATE TABLE IF NOT EXISTS project_context_setting ( ); CREATE INDEX IF NOT EXISTS idx_proj_ctx_rag_enabled ON project_context_setting (rag_enabled); - -ALTER TABLE project_context_setting - ADD CONSTRAINT fk_proj_ctx_project - FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE;