完善定价与套餐关联表结构
This commit is contained in:
@@ -228,7 +228,7 @@ create table admin_role (
|
||||
name text not null,
|
||||
description text,
|
||||
active bool not null default true,
|
||||
sort int not null default 0,
|
||||
sort int not null default 0,
|
||||
created_at timestamptz default current_timestamp,
|
||||
updated_at timestamptz default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
@@ -449,8 +449,8 @@ comment on column permission.deleted_at is '删除时间';
|
||||
-- link_user_role
|
||||
drop table if exists link_user_role cascade;
|
||||
create table link_user_role (
|
||||
id int generated by default as identity primary key,
|
||||
user_id int not null,
|
||||
id int generated by default as identity primary key,
|
||||
user_id int not null,
|
||||
user_role_id int not null
|
||||
);
|
||||
create index idx_link_user_role_user_id on link_user_role (user_id);
|
||||
@@ -465,9 +465,9 @@ comment on column link_user_role.user_role_id is '角色ID';
|
||||
-- link_admin_role
|
||||
drop table if exists link_admin_role cascade;
|
||||
create table link_admin_role (
|
||||
id int generated by default as identity primary key,
|
||||
admin_id int not null,
|
||||
admin_role_id int not null
|
||||
id int generated by default as identity primary key,
|
||||
admin_id int not null,
|
||||
admin_role_id int not null
|
||||
);
|
||||
create index idx_link_admin_role_admin_id on link_admin_role (admin_id);
|
||||
create index idx_link_admin_role_role_id on link_admin_role (admin_role_id);
|
||||
@@ -482,7 +482,7 @@ comment on column link_admin_role.admin_role_id is '角色ID';
|
||||
drop table if exists link_user_role_permission cascade;
|
||||
create table link_user_role_permission (
|
||||
id int generated by default as identity primary key,
|
||||
user_role_id int not null,
|
||||
user_role_id int not null,
|
||||
permission_id int not null
|
||||
);
|
||||
create index idx_link_user_role_permission_role_id on link_user_role_permission (user_role_id);
|
||||
@@ -498,7 +498,7 @@ comment on column link_user_role_permission.permission_id is '权限ID';
|
||||
drop table if exists link_admin_role_permission cascade;
|
||||
create table link_admin_role_permission (
|
||||
id int generated by default as identity primary key,
|
||||
admin_role_id int not null,
|
||||
admin_role_id int not null,
|
||||
permission_id int not null
|
||||
);
|
||||
create index idx_link_admin_role_permission_role_id on link_admin_role_permission (admin_role_id);
|
||||
@@ -720,30 +720,52 @@ comment on column product.created_at is '创建时间';
|
||||
comment on column product.updated_at is '更新时间';
|
||||
comment on column product.deleted_at is '删除时间';
|
||||
|
||||
-- product_sku
|
||||
drop table if exists product_sku cascade;
|
||||
create table product_sku (
|
||||
|
||||
-- product_discount
|
||||
drop table if exists product_discount cascade;
|
||||
create table product_discount (
|
||||
id int generated by default as identity primary key,
|
||||
product_id int not null,
|
||||
code text not null,
|
||||
name text not null,
|
||||
price decimal not null,
|
||||
discount float not null,
|
||||
name text,
|
||||
discount int,
|
||||
created_at timestamptz default current_timestamp,
|
||||
updated_at timestamptz default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
|
||||
-- product_discount表字段注释
|
||||
comment on table product_discount is '产品折扣表';
|
||||
comment on column product_discount.id is 'ID';
|
||||
comment on column product_discount.name is '折扣名称';
|
||||
comment on column product_discount.discount is '折扣,0 - 100 的整数,表示 xx 折';
|
||||
comment on column product_discount.created_at is '创建时间';
|
||||
comment on column product_discount.updated_at is '更新时间';
|
||||
comment on column product_discount.deleted_at is '删除时间';
|
||||
|
||||
-- product_sku
|
||||
drop table if exists product_sku cascade;
|
||||
create table product_sku (
|
||||
id int generated by default as identity primary key,
|
||||
product_id int not null,
|
||||
discount_id int,
|
||||
code text not null,
|
||||
name text not null,
|
||||
price decimal not null,
|
||||
created_at timestamptz default current_timestamp,
|
||||
updated_at timestamptz default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
create index idx_product_sku_product_id on product_sku (product_id) where deleted_at is null;
|
||||
create index idx_product_sku_discount_id on product_sku (discount_id) where deleted_at is null;
|
||||
create index idx_product_sku_code on product_sku (code) where deleted_at is null;
|
||||
|
||||
-- product_sku表字段注释
|
||||
comment on table product_sku is '产品SKU表';
|
||||
comment on column product_sku.id is 'SKU ID';
|
||||
comment on column product_sku.product_id is '产品ID';
|
||||
comment on column product_sku.discount_id is '折扣ID';
|
||||
comment on column product_sku.code is 'SKU 代码:格式为 key=value,key=value,...,其中,key:value 是 SKU 的属性,多个属性用逗号分隔';
|
||||
comment on column product_sku.name is 'SKU 可读名称';
|
||||
comment on column product_sku.price is '定价';
|
||||
comment on column product_sku.discount is '折扣,0 - 1 的小数,表示 xx 折';
|
||||
comment on column product_sku.created_at is '创建时间';
|
||||
comment on column product_sku.updated_at is '更新时间';
|
||||
comment on column product_sku.deleted_at is '删除时间';
|
||||
@@ -754,21 +776,20 @@ create table product_sku_user (
|
||||
id int generated by default as identity primary key,
|
||||
user_id int not null,
|
||||
product_sku_id int not null,
|
||||
price decimal,
|
||||
discount float,
|
||||
discount_id int,
|
||||
created_at timestamptz default current_timestamp,
|
||||
updated_at timestamptz default current_timestamp
|
||||
);
|
||||
create index idx_product_sku_user_user_id on product_sku_user (user_id);
|
||||
create index idx_product_sku_user_product_sku_id on product_sku_user (product_sku_id);
|
||||
create index idx_product_sku_user_discount_id on product_sku_user (discount_id);
|
||||
|
||||
-- product_sku_user表字段注释
|
||||
comment on table product_sku_user is '用户产品SKU表';
|
||||
comment on column product_sku_user.id is 'ID';
|
||||
comment on column product_sku_user.user_id is '用户ID';
|
||||
comment on column product_sku_user.product_sku_id is '产品SKU ID';
|
||||
comment on column product_sku_user.price is '定价';
|
||||
comment on column product_sku_user.discount is '折扣,0 - 1 的小数,表示 xx 折';
|
||||
comment on column product_sku_user.discount_id is '折扣ID';
|
||||
comment on column product_sku_user.created_at is '创建时间';
|
||||
comment on column product_sku_user.updated_at is '更新时间';
|
||||
|
||||
@@ -777,9 +798,10 @@ drop table if exists resource cascade;
|
||||
create table resource (
|
||||
id int generated by default as identity primary key,
|
||||
user_id int not null,
|
||||
resource_no text,
|
||||
active bool not null default true,
|
||||
resource_no text not null,
|
||||
code text,
|
||||
type int not null,
|
||||
active bool not null default true,
|
||||
created_at timestamptz default current_timestamp,
|
||||
updated_at timestamptz default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
@@ -787,6 +809,7 @@ create table resource (
|
||||
create unique index udx_resource_resource_no on resource (resource_no);
|
||||
create index idx_resource_user_id on resource (user_id) where deleted_at is null;
|
||||
create index idx_resource_created_at on resource (created_at) where deleted_at is null;
|
||||
create index idx_resource_code on resource (code) where deleted_at is null;
|
||||
|
||||
-- resource表字段注释
|
||||
comment on table resource is '套餐表';
|
||||
@@ -795,6 +818,7 @@ comment on column resource.user_id is '用户ID';
|
||||
comment on column resource.resource_no is '套餐编号';
|
||||
comment on column resource.active is '套餐状态';
|
||||
comment on column resource.type is '套餐类型:1-短效动态,2-长效动态';
|
||||
comment on column resource.code is '产品编码';
|
||||
comment on column resource.created_at is '创建时间';
|
||||
comment on column resource.updated_at is '更新时间';
|
||||
comment on column resource.deleted_at is '删除时间';
|
||||
@@ -804,6 +828,7 @@ drop table if exists resource_short cascade;
|
||||
create table resource_short (
|
||||
id int generated by default as identity primary key,
|
||||
resource_id int not null,
|
||||
code text,
|
||||
live int not null,
|
||||
type int not null,
|
||||
quota int not null,
|
||||
@@ -813,11 +838,13 @@ create table resource_short (
|
||||
last_at timestamptz
|
||||
);
|
||||
create index idx_resource_short_resource_id on resource_short (resource_id);
|
||||
create index idx_resource_short_code on resource_short (code);
|
||||
|
||||
-- resource_short表字段注释
|
||||
comment on table resource_short is '短效动态套餐表';
|
||||
comment on column resource_short.id is 'ID';
|
||||
comment on column resource_short.resource_id is '套餐ID';
|
||||
comment on column resource_short.code is '产品套餐编码';
|
||||
comment on column resource_short.live is '可用时长(秒)';
|
||||
comment on column resource_short.type is '套餐类型:1-包时,2-包量';
|
||||
comment on column resource_short.quota is '每日配额(包时)或总配额(包量)';
|
||||
@@ -831,6 +858,7 @@ drop table if exists resource_long cascade;
|
||||
create table resource_long (
|
||||
id int generated by default as identity primary key,
|
||||
resource_id int not null,
|
||||
code text,
|
||||
live int not null,
|
||||
type int not null,
|
||||
quota int not null,
|
||||
@@ -840,11 +868,13 @@ create table resource_long (
|
||||
last_at timestamptz
|
||||
);
|
||||
create index idx_resource_long_resource_id on resource_long (resource_id);
|
||||
create index idx_resource_long_code on resource_long (code);
|
||||
|
||||
-- resource_long表字段注释
|
||||
comment on table resource_long is '长效动态套餐表';
|
||||
comment on column resource_long.id is 'ID';
|
||||
comment on column resource_long.resource_id is '套餐ID';
|
||||
comment on column resource_long.code is '产品套餐编码';
|
||||
comment on column resource_long.live is '可用时长(小时)';
|
||||
comment on column resource_long.type is '套餐类型:1-包时,2-包量';
|
||||
comment on column resource_long.quota is '每日配额(包时)或总配额(包量)';
|
||||
@@ -1113,11 +1143,15 @@ alter table coupon
|
||||
-- product_sku表外键
|
||||
alter table product_sku
|
||||
add constraint fk_product_sku_product_id foreign key (product_id) references product (id) on delete cascade;
|
||||
alter table product_sku
|
||||
add constraint fk_product_sku_discount_id foreign key (discount_id) references product_discount (id) on delete restrict;
|
||||
|
||||
-- product_sku_user表外键
|
||||
alter table product_sku_user
|
||||
add constraint fk_product_sku_user_user_id foreign key (user_id) references "user" (id) on delete cascade;
|
||||
alter table product_sku_user
|
||||
add constraint fk_product_sku_user_product_sku_id foreign key (product_sku_id) references product_sku (id) on delete cascade;
|
||||
alter table product_sku_user
|
||||
add constraint fk_product_sku_user_discount_id foreign key (discount_id) references product_discount (id) on delete restrict;
|
||||
|
||||
-- endregion
|
||||
|
||||
Reference in New Issue
Block a user