feat(migration): 行动收件箱菜单种子数据 + 权限关联
This commit is contained in:
@@ -99,6 +99,7 @@ mod m20260430_000096_create_medication_reminder;
|
|||||||
mod m20260501_000097_seed_menu_permissions;
|
mod m20260501_000097_seed_menu_permissions;
|
||||||
mod m20260501_000098_create_ai_suggestion;
|
mod m20260501_000098_create_ai_suggestion;
|
||||||
mod m20260501_000099_create_ai_risk_threshold;
|
mod m20260501_000099_create_ai_risk_threshold;
|
||||||
|
mod m20260501_000100_seed_action_inbox_menu;
|
||||||
|
|
||||||
pub struct Migrator;
|
pub struct Migrator;
|
||||||
|
|
||||||
@@ -205,6 +206,7 @@ impl MigratorTrait for Migrator {
|
|||||||
Box::new(m20260501_000097_seed_menu_permissions::Migration),
|
Box::new(m20260501_000097_seed_menu_permissions::Migration),
|
||||||
Box::new(m20260501_000098_create_ai_suggestion::Migration),
|
Box::new(m20260501_000098_create_ai_suggestion::Migration),
|
||||||
Box::new(m20260501_000099_create_ai_risk_threshold::Migration),
|
Box::new(m20260501_000099_create_ai_risk_threshold::Migration),
|
||||||
|
Box::new(m20260501_000100_seed_action_inbox_menu::Migration),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
|
#[derive(DeriveMigrationName)]
|
||||||
|
pub struct Migration;
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl MigrationTrait for Migration {
|
||||||
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
let db = manager.get_connection();
|
||||||
|
|
||||||
|
db.execute_unprepared(
|
||||||
|
r#"
|
||||||
|
INSERT INTO menus (id, tenant_id, parent_id, title, path, icon, sort_order,
|
||||||
|
created_at, updated_at, is_active)
|
||||||
|
SELECT
|
||||||
|
'b0000003-0000-7000-8000-000000000020'::uuid,
|
||||||
|
t.id,
|
||||||
|
(SELECT id FROM menus WHERE path = '/health' AND tenant_id = t.id LIMIT 1),
|
||||||
|
'行动收件箱',
|
||||||
|
'/health/action-inbox',
|
||||||
|
'InboxOutlined',
|
||||||
|
36,
|
||||||
|
NOW(), NOW(), true
|
||||||
|
FROM tenants t
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1 FROM menus
|
||||||
|
WHERE path = '/health/action-inbox' AND tenant_id = t.id
|
||||||
|
)
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
db.execute_unprepared(
|
||||||
|
r#"
|
||||||
|
INSERT INTO role_permissions (role_id, permission_code, tenant_id)
|
||||||
|
SELECT r.id, 'health.action-inbox.list', t.id
|
||||||
|
FROM tenants t
|
||||||
|
JOIN roles r ON r.tenant_id = t.id AND r.code = 'admin'
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1 FROM role_permissions rp
|
||||||
|
WHERE rp.permission_code = 'health.action-inbox.list'
|
||||||
|
AND rp.role_id = r.id
|
||||||
|
)
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
let db = manager.get_connection();
|
||||||
|
db.execute_unprepared(
|
||||||
|
"DELETE FROM menus WHERE path = '/health/action-inbox'",
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user