重构提取逻辑,新增 area 表
This commit is contained in:
@@ -634,6 +634,31 @@ comment on column proxy.created_at is '创建时间';
|
||||
comment on column proxy.updated_at is '更新时间';
|
||||
comment on column proxy.deleted_at is '删除时间';
|
||||
|
||||
-- area
|
||||
drop table if exists area cascade;
|
||||
create table area (
|
||||
id int generated by default as identity primary key,
|
||||
name text not null,
|
||||
level int not null,
|
||||
parent_id int,
|
||||
created_at timestamptz default current_timestamp,
|
||||
updated_at timestamptz default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
create index idx_area_level on area (level) where deleted_at is null;
|
||||
create index idx_area_parent_id on area (parent_id) where deleted_at is null;
|
||||
create index idx_area_created_at on area (created_at) where deleted_at is null;
|
||||
|
||||
-- area表字段注释
|
||||
comment on table area is '地区表';
|
||||
comment on column area.id is '地区ID';
|
||||
comment on column area.name is '地区名称';
|
||||
comment on column area.level is '地区层级:1-省,2-市';
|
||||
comment on column area.parent_id is '父级地区ID';
|
||||
comment on column area.created_at is '创建时间';
|
||||
comment on column area.updated_at is '更新时间';
|
||||
comment on column area.deleted_at is '删除时间';
|
||||
|
||||
-- edge
|
||||
drop table if exists edge cascade;
|
||||
create table edge (
|
||||
@@ -644,8 +669,7 @@ create table edge (
|
||||
ip inet not null,
|
||||
port int,
|
||||
isp int not null,
|
||||
prov text not null,
|
||||
city text not null,
|
||||
area_id int not null,
|
||||
status int not null default 0,
|
||||
rtt int default 0,
|
||||
loss int default 0,
|
||||
@@ -655,8 +679,7 @@ create table edge (
|
||||
);
|
||||
create unique index udx_edge_mac on edge (mac) where deleted_at is null;
|
||||
create index idx_edge_isp on edge (isp) where deleted_at is null;
|
||||
create index idx_edge_prov on edge (prov) where deleted_at is null;
|
||||
create index idx_edge_city on edge (city) where deleted_at is null;
|
||||
create index idx_edge_area_id on edge (area_id) where deleted_at is null;
|
||||
create index idx_edge_created_at on edge (created_at) where deleted_at is null;
|
||||
|
||||
-- edge表字段注释
|
||||
@@ -668,8 +691,7 @@ comment on column edge.mac is '节点 mac 地址或 GOST chain 名称';
|
||||
comment on column edge.ip is '节点地址或 GOST chain addr 的 IP';
|
||||
comment on column edge.port is 'GOST chain addr 的端口';
|
||||
comment on column edge.isp is '运营商:1-电信,2-联通,3-移动';
|
||||
comment on column edge.prov is '省份';
|
||||
comment on column edge.city is '城市';
|
||||
comment on column edge.area_id is '城市地区ID';
|
||||
comment on column edge.status is '节点状态:0-离线,1-正常';
|
||||
comment on column edge.rtt is '最近平均延迟';
|
||||
comment on column edge.loss is '最近丢包率';
|
||||
@@ -1237,6 +1259,10 @@ alter table channel
|
||||
add constraint fk_channel_user_id foreign key (user_id) references "user" (id) on delete cascade;
|
||||
alter table channel
|
||||
add constraint fk_channel_proxy_id foreign key (proxy_id) references proxy (id) on delete set null;
|
||||
alter table area
|
||||
add constraint fk_area_parent_id foreign key (parent_id) references area (id) on delete set null;
|
||||
alter table edge
|
||||
add constraint fk_edge_area_id foreign key (area_id) references area (id) on delete restrict;
|
||||
alter table channel
|
||||
add constraint fk_channel_edge_id foreign key (edge_id) references edge (id) on delete set null;
|
||||
alter table channel
|
||||
|
||||
Reference in New Issue
Block a user