diff --git a/config/sql/init.sql b/config/sql/init.sql index 08e3831..d63b8cc 100644 --- a/config/sql/init.sql +++ b/config/sql/init.sql @@ -1,71 +1,71 @@ -- nodes -DROP TABLE IF EXISTS nodes CASCADE; -CREATE TABLE nodes ( - id SERIAL PRIMARY KEY, - name VARCHAR(255) NOT NULL UNIQUE, - provider VARCHAR(255) NOT NULL, - location VARCHAR(255) NOT NULL, - ip_address VARCHAR(255) NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - deleted_at TIMESTAMP +drop table if exists nodes cascade; +create table nodes ( + id serial primary key, + name varchar(255) not null unique, + provider varchar(255) not null, + location varchar(255) not null, + ip_address varchar(255) not null, + created_at timestamp default current_timestamp, + updated_at timestamp default current_timestamp, + deleted_at timestamp ); -CREATE INDEX devices_provider_index ON nodes (provider); -CREATE INDEX devices_location_index ON nodes (location); +create index devices_provider_index on nodes (provider); +create index devices_location_index on nodes (location); -- users -DROP TABLE IF EXISTS users CASCADE; -CREATE TABLE users ( - id SERIAL PRIMARY KEY, - password VARCHAR(255) NOT NULL, - username VARCHAR(255) NOT NULL UNIQUE, - email VARCHAR(255) NOT NULL UNIQUE, - phone VARCHAR(255) NOT NULL UNIQUE, - name VARCHAR(255) NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - deleted_at TIMESTAMP +drop table if exists users cascade; +create table users ( + id serial primary key, + password varchar(255) not null, + username varchar(255) not null unique, + email varchar(255) not null unique, + phone varchar(255) not null unique, + name varchar(255) not null, + created_at timestamp default current_timestamp, + updated_at timestamp default current_timestamp, + deleted_at timestamp ); -- user_ips -DROP TABLE IF EXISTS user_ips CASCADE; -CREATE TABLE user_ips ( - id SERIAL PRIMARY KEY, - user_id int NOT NULL REFERENCES users (id) - ON UPDATE CASCADE - ON DELETE CASCADE, - ip_address VARCHAR(255) NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - deleted_at TIMESTAMP +drop table if exists user_ips cascade; +create table user_ips ( + id serial primary key, + user_id int not null references users (id) + on update cascade + on delete cascade, + ip_address varchar(255) not null, + created_at timestamp default current_timestamp, + updated_at timestamp default current_timestamp, + deleted_at timestamp ); -CREATE INDEX user_ips_user_id_index ON user_ips (user_id); -CREATE INDEX user_ips_ip_address_index ON user_ips (ip_address); +create index user_ips_user_id_index on user_ips (user_id); +create index user_ips_ip_address_index on user_ips (ip_address); -- channel -DROP TABLE IF EXISTS channels CASCADE; -CREATE TABLE channels ( - id SERIAL PRIMARY KEY, - user_id int NOT NULL REFERENCES users (id) - ON UPDATE CASCADE - ON DELETE CASCADE, - node_id int NOT NULL REFERENCES nodes (id) -- - ON UPDATE CASCADE -- - ON DELETE SET NULL, -- 节点删除后,用户侧需要保留提取记录 +drop table if exists channels cascade; +create table channels ( + id serial primary key, + user_id int not null references users (id) + on update cascade + on delete cascade, + node_id int not null references nodes (id) -- + on update cascade -- + on delete set null, -- 节点删除后,用户侧需要保留提取记录 node_port int, - protocol VARCHAR(255), + protocol varchar(255), auth_ip bool, auth_pass bool, - username VARCHAR(255), - password VARCHAR(255), - expiration TIMESTAMP NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - deleted_at TIMESTAMP + username varchar(255) unique, + password varchar(255), + expiration timestamp not null, + created_at timestamp default current_timestamp, + updated_at timestamp default current_timestamp, + deleted_at timestamp ); -CREATE INDEX channel_user_id_index ON channels (user_id); -CREATE INDEX channel_node_id_index ON channels (node_id); -CREATE INDEX channel_username_index ON channels (username); +create index channel_user_id_index on channels (user_id); +create index channel_node_id_index on channels (node_id); +create index channel_username_index on channels (username); -- ==================== -- 填充数据 diff --git a/config/sql/临时迁移记录.txt b/config/sql/临时迁移记录.txt deleted file mode 100644 index bec9e8b..0000000 --- a/config/sql/临时迁移记录.txt +++ /dev/null @@ -1,4 +0,0 @@ -==================== -删除 channels.target_snapshot 不需要目标地址快照 -添加 channels.auth_ip 是否验证白名单 -添加 channels.auth_pass 是否验证密码 \ No newline at end of file