fix(saas): migration idempotency fixes + SCHEMA_VERSION bump to 14
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
- Add IF NOT EXISTS to accounts_template_assignment ALTER COLUMN - Add IF NOT EXISTS to webhooks CREATE INDEX statements - Add created_at/updated_at columns + ON CONFLICT DO NOTHING to industry templates - Bump SCHEMA_VERSION 13→14 to force migration re-run on existing DB
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
-- 用户选择行业模板后记录分配关系,用于跟踪和跳过 onboarding
|
-- 用户选择行业模板后记录分配关系,用于跟踪和跳过 onboarding
|
||||||
-- ON DELETE SET NULL: 模板被删除时不影响账户
|
-- ON DELETE SET NULL: 模板被删除时不影响账户
|
||||||
|
|
||||||
ALTER TABLE accounts ADD COLUMN assigned_template_id TEXT
|
ALTER TABLE accounts ADD COLUMN IF NOT EXISTS assigned_template_id TEXT
|
||||||
REFERENCES agent_templates(id) ON DELETE SET NULL;
|
REFERENCES agent_templates(id) ON DELETE SET NULL;
|
||||||
|
|
||||||
COMMENT ON COLUMN accounts.assigned_template_id IS
|
COMMENT ON COLUMN accounts.assigned_template_id IS
|
||||||
|
|||||||
@@ -23,6 +23,6 @@ CREATE TABLE IF NOT EXISTS webhook_deliveries (
|
|||||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_webhook_subscriptions_account ON webhook_subscriptions(account_id);
|
CREATE INDEX IF NOT EXISTS idx_webhook_subscriptions_account ON webhook_subscriptions(account_id);
|
||||||
CREATE INDEX idx_webhook_subscriptions_events ON webhook_subscriptions USING gin(events);
|
CREATE INDEX IF NOT EXISTS idx_webhook_subscriptions_events ON webhook_subscriptions USING gin(events);
|
||||||
CREATE INDEX idx_webhook_deliveries_pending ON webhook_deliveries(subscription_id) WHERE delivered_at IS NULL;
|
CREATE INDEX IF NOT EXISTS idx_webhook_deliveries_pending ON webhook_deliveries(subscription_id) WHERE delivered_at IS NULL;
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ INSERT INTO agent_templates (
|
|||||||
model, system_prompt, tools, capabilities, temperature, max_tokens,
|
model, system_prompt, tools, capabilities, temperature, max_tokens,
|
||||||
visibility, status, current_version,
|
visibility, status, current_version,
|
||||||
soul_content, scenarios, welcome_message, quick_commands,
|
soul_content, scenarios, welcome_message, quick_commands,
|
||||||
personality, communication_style, source_id, version
|
personality, communication_style, source_id, version,
|
||||||
|
created_at, updated_at
|
||||||
) VALUES (
|
) VALUES (
|
||||||
'edu-teacher-001',
|
'edu-teacher-001',
|
||||||
'教学助手',
|
'教学助手',
|
||||||
@@ -55,8 +56,9 @@ INSERT INTO agent_templates (
|
|||||||
'friendly',
|
'friendly',
|
||||||
'温暖、耐心、善于用易懂的语言解释复杂概念',
|
'温暖、耐心、善于用易懂的语言解释复杂概念',
|
||||||
'education-teacher',
|
'education-teacher',
|
||||||
1
|
1,
|
||||||
);
|
NOW(), NOW()
|
||||||
|
) ON CONFLICT (id) DO NOTHING;
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- 2. Healthcare — 医疗行政助手
|
-- 2. Healthcare — 医疗行政助手
|
||||||
@@ -66,7 +68,8 @@ INSERT INTO agent_templates (
|
|||||||
model, system_prompt, tools, capabilities, temperature, max_tokens,
|
model, system_prompt, tools, capabilities, temperature, max_tokens,
|
||||||
visibility, status, current_version,
|
visibility, status, current_version,
|
||||||
soul_content, scenarios, welcome_message, quick_commands,
|
soul_content, scenarios, welcome_message, quick_commands,
|
||||||
personality, communication_style, source_id, version
|
personality, communication_style, source_id, version,
|
||||||
|
created_at, updated_at
|
||||||
) VALUES (
|
) VALUES (
|
||||||
'healthcare-admin-001',
|
'healthcare-admin-001',
|
||||||
'医疗行政助手',
|
'医疗行政助手',
|
||||||
@@ -111,8 +114,9 @@ INSERT INTO agent_templates (
|
|||||||
'professional',
|
'professional',
|
||||||
'专业、准确、注重细节,提供技术深度和可操作建议',
|
'专业、准确、注重细节,提供技术深度和可操作建议',
|
||||||
'healthcare-admin',
|
'healthcare-admin',
|
||||||
1
|
1,
|
||||||
);
|
NOW(), NOW()
|
||||||
|
) ON CONFLICT (id) DO NOTHING;
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- 3. Design (Shantou) — 设计助手
|
-- 3. Design (Shantou) — 设计助手
|
||||||
@@ -122,7 +126,8 @@ INSERT INTO agent_templates (
|
|||||||
model, system_prompt, tools, capabilities, temperature, max_tokens,
|
model, system_prompt, tools, capabilities, temperature, max_tokens,
|
||||||
visibility, status, current_version,
|
visibility, status, current_version,
|
||||||
soul_content, scenarios, welcome_message, quick_commands,
|
soul_content, scenarios, welcome_message, quick_commands,
|
||||||
personality, communication_style, source_id, version
|
personality, communication_style, source_id, version,
|
||||||
|
created_at, updated_at
|
||||||
) VALUES (
|
) VALUES (
|
||||||
'design-shantou-001',
|
'design-shantou-001',
|
||||||
'设计助手',
|
'设计助手',
|
||||||
@@ -167,5 +172,6 @@ INSERT INTO agent_templates (
|
|||||||
'creative',
|
'creative',
|
||||||
'富有创意、思维开放,鼓励探索新想法和解决方案',
|
'富有创意、思维开放,鼓励探索新想法和解决方案',
|
||||||
'design-shantou',
|
'design-shantou',
|
||||||
1
|
1,
|
||||||
);
|
NOW(), NOW()
|
||||||
|
) ON CONFLICT (id) DO NOTHING;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use sqlx::PgPool;
|
|||||||
use crate::config::DatabaseConfig;
|
use crate::config::DatabaseConfig;
|
||||||
use crate::error::SaasResult;
|
use crate::error::SaasResult;
|
||||||
|
|
||||||
const SCHEMA_VERSION: i32 = 13;
|
const SCHEMA_VERSION: i32 = 14;
|
||||||
|
|
||||||
/// 初始化数据库
|
/// 初始化数据库
|
||||||
pub async fn init_db(config: &DatabaseConfig) -> SaasResult<PgPool> {
|
pub async fn init_db(config: &DatabaseConfig) -> SaasResult<PgPool> {
|
||||||
|
|||||||
Reference in New Issue
Block a user