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
This commit is contained in:
ZhenYi 2026-05-11 01:31:33 +08:00
parent 4d5caffe0b
commit b1ef024724
6 changed files with 2 additions and 30 deletions

View File

@ -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),

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;