优化数据库结构与数据插入逻辑

This commit is contained in:
2025-04-12 18:03:44 +08:00
parent 438a55cc3e
commit 8c268fd7a9
28 changed files with 218 additions and 213 deletions

View File

@@ -424,15 +424,15 @@ comment on column proxy.deleted_at is '删除时间';
drop table if exists node cascade;
create table node (
id serial primary key,
proxy_id int references proxy (id)
on update cascade
on delete cascade,
version int not null,
name varchar(255) not null unique,
host varchar(255) not null,
isp int not null,
prov varchar(255) not null,
city varchar(255) not null,
proxy_id int references proxy (id)
on update cascade
on delete cascade,
proxy_port int,
status int not null default 0,
rtt int default 0,
@@ -458,7 +458,7 @@ comment on column node.prov is '省份';
comment on column node.city is '城市';
comment on column node.proxy_id is '代理ID';
comment on column node.proxy_port is '代理端口';
comment on column node.status is '节点状态:1-正常,0-离线';
comment on column node.status is '节点状态0-离线1-正常';
comment on column node.rtt is '延迟';
comment on column node.loss is '丢包率';
comment on column node.created_at is '创建时间';
@@ -593,6 +593,7 @@ create table resource (
on delete cascade,
resource_no varchar(255) unique,
active bool not null default true,
type int not null,
created_at timestamp default current_timestamp,
updated_at timestamp default current_timestamp,
deleted_at timestamp
@@ -600,6 +601,7 @@ create table resource (
create index resource_user_id_index on resource (user_id);
create index resource_resource_no_index on resource (resource_no);
create index resource_active_index on resource (active);
create index resource_type_index on resource (type);
create index resource_deleted_at_index on resource (deleted_at);
-- resource表字段注释
@@ -608,6 +610,7 @@ comment on column resource.id is '套餐ID';
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-隧道3-独享';
comment on column resource.created_at is '创建时间';
comment on column resource.updated_at is '更新时间';
comment on column resource.deleted_at is '删除时间';
@@ -626,13 +629,9 @@ create table resource_pss (
used int not null default 0,
daily_limit int not null default 0,
daily_used int not null default 0,
daily_last timestamp,
created_at timestamp default current_timestamp,
updated_at timestamp default current_timestamp,
deleted_at timestamp
daily_last timestamp
);
create index resource_pss_resource_id_index on resource_pss (resource_id);
create index resource_pss_deleted_at_index on resource_pss (deleted_at);
-- resource_pss表字段注释
comment on table resource_pss is '动态代理套餐表';
@@ -646,9 +645,6 @@ comment on column resource_pss.expire is '过期时间';
comment on column resource_pss.daily_limit is '每日限制';
comment on column resource_pss.daily_used is '今日已用数量';
comment on column resource_pss.daily_last is '今日最后使用时间';
comment on column resource_pss.created_at is '创建时间';
comment on column resource_pss.updated_at is '更新时间';
comment on column resource_pss.deleted_at is '删除时间';
-- resource_psr
drop table if exists resource_psr cascade;
@@ -660,13 +656,9 @@ create table resource_psr (
live int,
conn int,
expire timestamp,
used bool,
created_at timestamp default current_timestamp,
updated_at timestamp default current_timestamp,
deleted_at timestamp
used bool
);
create index resource_psr_resource_id_index on resource_psr (resource_id);
create index resource_psr_deleted_at_index on resource_psr (deleted_at);
-- resource_psr表字段注释
comment on table resource_psr is '隧道代理套餐表';
@@ -676,9 +668,6 @@ comment on column resource_psr.live is '轮换周期(秒)';
comment on column resource_psr.conn is '最大连接数';
comment on column resource_psr.expire is '过期时间';
comment on column resource_psr.used is '是否已使用';
comment on column resource_psr.created_at is '创建时间';
comment on column resource_psr.updated_at is '更新时间';
comment on column resource_psr.deleted_at is '删除时间';
-- resource_pps
drop table if exists resource_pps cascade;
@@ -686,21 +675,14 @@ create table resource_pps (
id serial primary key,
resource_id int not null references resource (id)
on update cascade
on delete cascade,
created_at timestamp default current_timestamp,
updated_at timestamp default current_timestamp,
deleted_at timestamp
on delete cascade
);
create index resource_pps_resource_id_index on resource_pps (resource_id);
create index resource_pps_deleted_at_index on resource_pps (deleted_at);
-- resource_pps表字段注释
comment on table resource_pps is '独享代理套餐表';
comment on column resource_pps.id is 'ID';
comment on column resource_pps.resource_id is '套餐ID';
comment on column resource_pps.created_at is '创建时间';
comment on column resource_pps.updated_at is '更新时间';
comment on column resource_pps.deleted_at is '删除时间';
-- endregion