Files
workspace/code/fms/sql/smoke_delete_setup.sql
2026-09-19 21:17:02 +08:00

64 lines
2.6 KiB
Transact-SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* ============================================================================
删除策略冒烟测试夹具(可重复执行)
----------------------------------------------------------------------------
建一对专用临时业务表 + 模块配置 + 删除规则,用于验证删除引擎:
smoke_order 主单(b_id varchar 业务键)
smoke_order_item 明细(b_item_id 主键,b_order_id 外键指向主单)
覆盖场景:
1. cascade:删主单连带删明细
2. restrict:明细被引用时拒绝删主单
3. SQL 规则:命中即整批拒绝
4. direct:按表直删
清理见 smoke_delete_teardown.sql。
============================================================================ */
if object_id('dbo.smoke_order_item', 'U') is null
begin
create table dbo.smoke_order_item (
b_item_id varchar(50) not null primary key,
b_order_id varchar(50) not null,
b_name nvarchar(100) null
);
end
GO
if object_id('dbo.smoke_order', 'U') is null
begin
create table dbo.smoke_order (
b_id varchar(50) not null primary key,
b_no nvarchar(50) null,
b_status varchar(20) null
);
end
GO
/* 模块配置:主单 */
if not exists (select 1 from dbo.s_module where b_id = 'smoke_order')
begin
insert into dbo.s_module (b_id, b_parent_id, b_depth, b_path, b_name, b_module_type, b_view_table, b_save_table, b_key_field, b_canuse, b_xh)
values ('smoke_order', null, 0, 'smoke_order', N'冒烟测试主单', 'data', 'smoke_order', 'smoke_order', 'b_id', 1, 9001);
end
GO
/* 模块配置:明细 */
if not exists (select 1 from dbo.s_module where b_id = 'smoke_order_item')
begin
insert into dbo.s_module (b_id, b_parent_id, b_depth, b_path, b_name, b_module_type, b_view_table, b_save_table, b_key_field, b_canuse, b_xh)
values ('smoke_order_item', null, 0, 'smoke_order_item', N'冒烟测试明细', 'data', 'smoke_order_item', 'smoke_order_item', 'b_item_id', 1, 9002);
end
GO
/* 关系:明细 → 主单,many_to_one。
按设计 §3.2,many_to_one 的外键在源字段:源字段 b_order_id 是明细表里的外键列,
目标字段 b_id 是主单被引用的列。删除主单时,明细(引用方)被 cascade 连带删除。 */
delete from dbo.s_relation where b_source_module_id = 'smoke_order_item' and b_target_module_id = 'smoke_order';
GO
insert into dbo.s_relation
(b_source_module_id, b_source_field, b_target_module_id, b_target_field, b_relation_type, b_on_delete, b_canuse, b_xh)
values
('smoke_order_item', 'b_order_id', 'smoke_order', 'b_id', 'many_to_one', 'cascade', 1, 10);
GO