20260703173210
This commit is contained in:
1 parent
d0f7f0d3d8
commit
3556d5e8c1
15 files changed
+853
-143
No files matched your search
@@ -1,7 +1,6 @@
|
||||
drop table if exists b_clothing_tag_relation;
|
||||
drop table if exists b_clothing_outfit_clothes;
|
||||
drop table if exists b_clothing_tag;
|
||||
drop table if exists b_clothing_tag_group;
|
||||
drop table if exists b_clothing_category;
|
||||
drop table if exists b_clothing_outfit;
|
||||
drop table if exists b_clothing_clothes;
|
||||
@@ -12,6 +11,7 @@ create table b_clothing_clothes (
|
||||
name varchar(64) not null,
|
||||
image_file_key varchar(512) not null,
|
||||
category_id bigint,
|
||||
owner_id bigint,
|
||||
brand varchar(64) default '',
|
||||
remark varchar(512) default '',
|
||||
sort_number int not null default 0,
|
||||
@@ -29,6 +29,7 @@ create table b_clothing_outfit (
|
||||
cover_file_key varchar(512) default '',
|
||||
layout_json jsonb,
|
||||
category_id bigint,
|
||||
owner_id bigint,
|
||||
remark varchar(512) default '',
|
||||
sort_number int not null default 0,
|
||||
status smallint not null default 1,
|
||||
@@ -68,23 +69,10 @@ create table b_clothing_category (
|
||||
update_by bigint
|
||||
);
|
||||
|
||||
create table b_clothing_tag_group (
|
||||
id bigint primary key,
|
||||
family_id bigint not null,
|
||||
name varchar(32) not null,
|
||||
type smallint not null,
|
||||
sort_number int not null default 0,
|
||||
status smallint not null default 1,
|
||||
create_time timestamp,
|
||||
update_time timestamp,
|
||||
create_by bigint,
|
||||
update_by bigint
|
||||
);
|
||||
|
||||
create table b_clothing_tag (
|
||||
id bigint primary key,
|
||||
family_id bigint not null,
|
||||
tag_group_id bigint not null,
|
||||
parent_id bigint not null default 0,
|
||||
name varchar(32) not null,
|
||||
type smallint not null,
|
||||
color varchar(7) default '',
|
||||
@@ -111,9 +99,15 @@ create table b_clothing_tag_relation (
|
||||
create index idx_b_clothing_clothes_family_status_category
|
||||
on b_clothing_clothes (family_id, status, category_id, sort_number, id);
|
||||
|
||||
create index idx_b_clothing_clothes_family_owner
|
||||
on b_clothing_clothes (family_id, owner_id, id);
|
||||
|
||||
create index idx_b_clothing_outfit_family_status_category
|
||||
on b_clothing_outfit (family_id, status, category_id, sort_number, id);
|
||||
|
||||
create index idx_b_clothing_outfit_family_owner
|
||||
on b_clothing_outfit (family_id, owner_id, id);
|
||||
|
||||
create index idx_b_clothing_outfit_clothes_outfit
|
||||
on b_clothing_outfit_clothes (outfit_id, z_index, sort_number, id);
|
||||
|
||||
@@ -123,11 +117,8 @@ create index idx_b_clothing_outfit_clothes_clothes
|
||||
create index idx_b_clothing_category_family_type
|
||||
on b_clothing_category (family_id, status, type, sort_number, id);
|
||||
|
||||
create index idx_b_clothing_tag_group_family_type
|
||||
on b_clothing_tag_group (family_id, status, type, sort_number, id);
|
||||
|
||||
create index idx_b_clothing_tag_family_group
|
||||
on b_clothing_tag (family_id, status, type, tag_group_id, sort_number, id);
|
||||
create index idx_b_clothing_tag_family_parent
|
||||
on b_clothing_tag (family_id, status, type, parent_id, sort_number, id);
|
||||
|
||||
create index idx_b_clothing_tag_relation_target
|
||||
on b_clothing_tag_relation (family_id, target_type, target_id, tag_id);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
-- 增量迁移:给衣服和搭配表添加归属者字段
|
||||
-- 说明:owner_id 引用 b_family_member.user_id;可空;仅为归属标记,
|
||||
-- 数据仍为家庭共享,不做隔离。
|
||||
|
||||
alter table b_clothing_clothes add column if not exists owner_id bigint;
|
||||
alter table b_clothing_outfit add column if not exists owner_id bigint;
|
||||
|
||||
create index if not exists idx_b_clothing_clothes_family_owner
|
||||
on b_clothing_clothes (family_id, owner_id, id);
|
||||
|
||||
create index if not exists idx_b_clothing_outfit_family_owner
|
||||
on b_clothing_outfit (family_id, owner_id, id);
|
||||
@@ -0,0 +1,37 @@
|
||||
-- 增量迁移:合并 b_clothing_tag_group 与 b_clothing_tag 为单表(加 parent_id)
|
||||
-- 说明:parent_id = 0 表示标签组(父行);parent_id != 0 表示标签(子行),
|
||||
-- 指向所属组的 id。type(0=衣服/1=搭配)保留在所有行上。
|
||||
-- 应用方式:go run ./cmd/apply_sql app-go/db/clothing_merge_tag.sql
|
||||
|
||||
-- 1. 新增 parent_id 列
|
||||
alter table b_clothing_tag add column if not exists parent_id bigint not null default 0;
|
||||
|
||||
-- 2. 把旧 tag_group_id 搬到 parent_id(仅当列仍存在时执行)
|
||||
do $$
|
||||
begin
|
||||
if exists (
|
||||
select 1 from information_schema.columns
|
||||
where table_name = 'b_clothing_tag' and column_name = 'tag_group_id'
|
||||
) then
|
||||
update b_clothing_tag set parent_id = tag_group_id where parent_id = 0;
|
||||
end if;
|
||||
end $$;
|
||||
|
||||
-- 3. 把组数据搬进 b_clothing_tag(parent_id = 0)
|
||||
insert into b_clothing_tag
|
||||
(id, family_id, name, type, color, parent_id, sort_number, status,
|
||||
create_time, update_time, create_by, update_by)
|
||||
select id, family_id, name, type, '', 0, sort_number, status,
|
||||
create_time, update_time, create_by, update_by
|
||||
from b_clothing_tag_group
|
||||
on conflict (id) do nothing;
|
||||
|
||||
-- 4. 清理旧结构
|
||||
alter table b_clothing_tag drop column if exists tag_group_id;
|
||||
drop index if exists idx_b_clothing_tag_family_group;
|
||||
drop index if exists idx_b_clothing_tag_group_family_type;
|
||||
drop table if exists b_clothing_tag_group;
|
||||
|
||||
-- 5. 新索引
|
||||
create index if not exists idx_b_clothing_tag_family_parent
|
||||
on b_clothing_tag (family_id, status, type, parent_id, sort_number, id);
|
||||
Reference in new issue
Block a user