diff --git a/sql/wvp.sql b/sql/wvp.sql index 34d1360..020a5cf 100644 --- a/sql/wvp.sql +++ b/sql/wvp.sql @@ -6,11 +6,9 @@ CREATE DATABASE `wvp` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -USE `wvp`; - /*建表*/ -drop table IF EXISTS wvp_device; -create table IF NOT EXISTS wvp_device +drop table IF EXISTS wvp.wvp_device; +create table IF NOT EXISTS wvp.wvp_device ( id serial primary key, device_id character varying(50) not null, @@ -50,8 +48,8 @@ create table IF NOT EXISTS wvp_device constraint uk_device_device unique (device_id) ); -drop table IF EXISTS wvp_device_alarm; -create table IF NOT EXISTS wvp_device_alarm +drop table IF EXISTS wvp.wvp_device_alarm; +create table IF NOT EXISTS wvp.wvp_device_alarm ( id serial primary key, device_id character varying(50) not null, @@ -66,8 +64,8 @@ create table IF NOT EXISTS wvp_device_alarm create_time character varying(50) not null ); -drop table IF EXISTS wvp_device_mobile_position; -create table IF NOT EXISTS wvp_device_mobile_position +drop table IF EXISTS wvp.wvp_device_mobile_position; +create table IF NOT EXISTS wvp.wvp_device_mobile_position ( id serial primary key, device_id character varying(50) not null, @@ -83,8 +81,8 @@ create table IF NOT EXISTS wvp_device_mobile_position create_time character varying(50) ); -drop table IF EXISTS wvp_device_channel; -create table IF NOT EXISTS wvp_device_channel +drop table IF EXISTS wvp.wvp_device_channel; +create table IF NOT EXISTS wvp.wvp_device_channel ( id serial primary key, device_id character varying(50), @@ -176,8 +174,8 @@ create table IF NOT EXISTS wvp_device_channel constraint uk_wvp_unique_channel unique (gb_device_id) ); -drop table IF EXISTS wvp_media_server; -create table IF NOT EXISTS wvp_media_server +drop table IF EXISTS wvp.wvp_media_server; +create table IF NOT EXISTS wvp.wvp_media_server ( id character varying(255) primary key, ip character varying(50), @@ -216,8 +214,8 @@ create table IF NOT EXISTS wvp_media_server constraint uk_media_server_unique_ip_http_port unique (ip, http_port, server_id) ); -drop table IF EXISTS wvp_platform; -create table IF NOT EXISTS wvp_platform +drop table IF EXISTS wvp.wvp_platform; +create table IF NOT EXISTS wvp.wvp_platform ( id serial primary key, enable bool default false, @@ -257,8 +255,8 @@ create table IF NOT EXISTS wvp_platform constraint uk_platform_unique_server_gb_id unique (server_gb_id) ); -drop table IF EXISTS wvp_platform_channel; -create table IF NOT EXISTS wvp_platform_channel +drop table IF EXISTS wvp.wvp_platform_channel; +create table IF NOT EXISTS wvp.wvp_platform_channel ( id serial primary key, platform_id integer, @@ -301,8 +299,8 @@ create table IF NOT EXISTS wvp_platform_channel constraint uk_platform_gb_channel_device_id unique (custom_device_id) ); -drop table IF EXISTS wvp_platform_group; -create table IF NOT EXISTS wvp_platform_group +drop table IF EXISTS wvp.wvp_platform_group; +create table IF NOT EXISTS wvp.wvp_platform_group ( id serial primary key, platform_id integer, @@ -310,8 +308,8 @@ create table IF NOT EXISTS wvp_platform_group constraint uk_wvp_platform_group_platform_id_group_id unique (platform_id, group_id) ); -drop table IF EXISTS wvp_platform_region; -create table IF NOT EXISTS wvp_platform_region +drop table IF EXISTS wvp.wvp_platform_region; +create table IF NOT EXISTS wvp.wvp_platform_region ( id serial primary key, platform_id integer, @@ -319,8 +317,8 @@ create table IF NOT EXISTS wvp_platform_region constraint uk_wvp_platform_region_platform_id_group_id unique (platform_id, region_id) ); -drop table IF EXISTS wvp_stream_proxy; -create table IF NOT EXISTS wvp_stream_proxy +drop table IF EXISTS wvp.wvp_stream_proxy; +create table IF NOT EXISTS wvp.wvp_stream_proxy ( id serial primary key, type character varying(50), @@ -346,8 +344,8 @@ create table IF NOT EXISTS wvp_stream_proxy constraint uk_stream_proxy_app_stream unique (app, stream) ); -drop table IF EXISTS wvp_stream_push; -create table IF NOT EXISTS wvp_stream_push +drop table IF EXISTS wvp.wvp_stream_push; +create table IF NOT EXISTS wvp.wvp_stream_push ( id serial primary key, app character varying(255), @@ -364,8 +362,8 @@ create table IF NOT EXISTS wvp_stream_push constraint uk_stream_push_app_stream unique (app, stream) ); -drop table IF EXISTS wvp_cloud_record; -create table IF NOT EXISTS wvp_cloud_record +drop table IF EXISTS wvp.wvp_cloud_record; +create table IF NOT EXISTS wvp.wvp_cloud_record ( id serial primary key, app character varying(255), @@ -383,8 +381,8 @@ create table IF NOT EXISTS wvp_cloud_record time_len bigint ); -drop table IF EXISTS wvp_user; -create table IF NOT EXISTS wvp_user +drop table IF EXISTS wvp.wvp_user; +create table IF NOT EXISTS wvp.wvp_user ( id serial primary key, username character varying(255), @@ -396,8 +394,8 @@ create table IF NOT EXISTS wvp_user constraint uk_user_username unique (username) ); -drop table IF EXISTS wvp_user_role; -create table IF NOT EXISTS wvp_user_role +drop table IF EXISTS wvp.wvp_user_role; +create table IF NOT EXISTS wvp.wvp_user_role ( id serial primary key, name character varying(50), @@ -407,8 +405,8 @@ create table IF NOT EXISTS wvp_user_role ); -drop table IF EXISTS wvp_user_api_key; -create table IF NOT EXISTS wvp_user_api_key +drop table IF EXISTS wvp.wvp_user_api_key; +create table IF NOT EXISTS wvp.wvp_user_api_key ( id serial primary key, user_id bigint, @@ -423,14 +421,14 @@ create table IF NOT EXISTS wvp_user_api_key /*初始数据*/ -INSERT INTO wvp_user +INSERT INTO wvp.wvp_user VALUES (1, 'admin', '21232f297a57a5a743894a0e4a801fc3', 1, '2021-04-13 14:14:57', '2021-04-13 14:14:57', '3e80d1762a324d5b0ff636e0bd16f1e3'); -INSERT INTO wvp_user_role +INSERT INTO wvp.wvp_user_role VALUES (1, 'admin', '0', '2021-04-13 14:14:57', '2021-04-13 14:14:57'); -drop table IF EXISTS wvp_common_group; -create table IF NOT EXISTS wvp_common_group +drop table IF EXISTS wvp.wvp_common_group; +create table IF NOT EXISTS wvp.wvp_common_group ( id serial primary key, device_id varchar(50) NOT NULL, @@ -445,8 +443,8 @@ create table IF NOT EXISTS wvp_common_group constraint uk_common_group_device_platform unique (device_id) ); -drop table IF EXISTS wvp_common_region; -create table IF NOT EXISTS wvp_common_region +drop table IF EXISTS wvp.wvp_common_region; +create table IF NOT EXISTS wvp.wvp_common_region ( id serial primary key, device_id varchar(50) NOT NULL, @@ -458,8 +456,8 @@ create table IF NOT EXISTS wvp_common_region constraint uk_common_region_device_id unique (device_id) ); -drop table IF EXISTS wvp_record_plan; -create table IF NOT EXISTS wvp_record_plan +drop table IF EXISTS wvp.wvp_record_plan; +create table IF NOT EXISTS wvp.wvp_record_plan ( id serial primary key, snap bool default false, @@ -468,8 +466,8 @@ create table IF NOT EXISTS wvp_record_plan update_time character varying(50) ); -drop table IF EXISTS wvp_record_plan_item; -create table IF NOT EXISTS wvp_record_plan_item +drop table IF EXISTS wvp.wvp_record_plan_item; +create table IF NOT EXISTS wvp.wvp_record_plan_item ( id serial primary key, start int, @@ -480,8 +478,8 @@ create table IF NOT EXISTS wvp_record_plan_item update_time character varying(50) ); -drop table IF EXISTS wvp_jt_terminal; -create table IF NOT EXISTS wvp_jt_terminal ( +drop table IF EXISTS wvp.wvp_jt_terminal; +create table IF NOT EXISTS wvp.wvp_jt_terminal ( id serial primary key, phone_number character varying(50), terminal_id character varying(50), @@ -505,8 +503,8 @@ create table IF NOT EXISTS wvp_jt_terminal ( constraint uk_jt_device_id_device_id unique (id, phone_number) ); -drop table IF EXISTS wvp_jt_channel; -create table IF NOT EXISTS wvp_jt_channel ( +drop table IF EXISTS wvp.wvp_jt_channel; +create table IF NOT EXISTS wvp.wvp_jt_channel ( id serial primary key, terminal_db_id integer, channel_id integer, @@ -517,281 +515,6 @@ create table IF NOT EXISTS wvp_jt_channel ( constraint uk_jt_channel_id_device_id unique (terminal_db_id, channel_id) ); -/* -* 20240528 -*/ -CREATE PROCEDURE `wvp_20240528`() -BEGIN - IF NOT EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_media_server' and column_name = 'transcode_suffix') - THEN - ALTER TABLE wvp_media_server ADD transcode_suffix character varying(255); - END IF; - - IF not EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_media_server' and column_name = 'type') - THEN - alter table wvp_media_server - add type character varying(50) default 'zlm'; - END IF; - - IF not EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_media_server' and column_name = 'flv_port') - THEN - alter table wvp_media_server add flv_port integer; - END IF; - - IF not EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_media_server' and column_name = 'flv_ssl_port') - THEN - alter table wvp_media_server add flv_ssl_port integer; - END IF; - - IF not EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_media_server' and column_name = 'ws_flv_port') - THEN - alter table wvp_media_server add ws_flv_port integer; - END IF; - - IF not EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_media_server' and column_name = 'ws_flv_ssl_port') - THEN - alter table wvp_media_server add ws_flv_ssl_port integer; - END IF; -END; -call wvp_20240528(); -DROP PROCEDURE wvp_20240528; - -create table IF NOT EXISTS wvp_user_api_key ( - id serial primary key , - user_id bigint, - app character varying(255) , - api_key text, - expired_at bigint, - remark character varying(255), - enable bool default true, - create_time character varying(50), - update_time character varying(50) -); - -/* -* 20241222 -*/ -CREATE PROCEDURE `wvp_20241222`() -BEGIN - IF EXISTS (SELECT column_name FROM information_schema.STATISTICS - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device_channel' and INDEX_NAME = 'uk_wvp_device_channel_unique_device_channel') - THEN - alter table wvp_device_channel drop index uk_wvp_device_channel_unique_device_channel; - END IF; - - IF EXISTS (SELECT column_name FROM information_schema.STATISTICS - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device_channel' and INDEX_NAME = 'uk_wvp_unique_stream_push_id') - THEN - alter table wvp_device_channel drop index uk_wvp_unique_stream_push_id; - END IF; - - IF EXISTS (SELECT column_name FROM information_schema.STATISTICS - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device_channel' and INDEX_NAME = 'uk_wvp_unique_stream_proxy_id') - THEN - alter table wvp_device_channel drop index uk_wvp_unique_stream_proxy_id; - END IF; - - IF not EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device_channel' and column_name = 'data_type') - THEN - alter table wvp_device_channel add data_type integer not null; - END IF; - - IF not EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device_channel' and column_name = 'data_device_id') - THEN - alter table wvp_device_channel add data_device_id integer not null; - END IF; - - IF EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device_channel' and column_name = 'device_db_id') - THEN - update wvp_device_channel wdc INNER JOIN - (SELECT id, device_db_id from wvp_device_channel where device_db_id is not null ) ct on ct.id = wdc.id - set wdc.data_type = 1, wdc.data_device_id = ct.device_db_id where wdc.device_db_id is not null; - alter table wvp_device_channel drop device_db_id; - END IF; - - IF EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device_channel' and column_name = 'stream_push_id') - THEN - update wvp_device_channel wdc INNER JOIN - (SELECT id, stream_push_id from wvp_device_channel where stream_push_id is not null ) ct on ct.id = wdc.id - set wdc.data_type = 2, wdc.data_device_id = ct.stream_push_id where wdc.stream_push_id is not null; - alter table wvp_device_channel drop stream_push_id; - END IF; - - IF EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device_channel' and column_name = 'stream_proxy_id') - THEN - update wvp_device_channel wdc INNER JOIN - (SELECT id, stream_proxy_id from wvp_device_channel where stream_proxy_id is not null ) ct on ct.id = wdc.id - set wdc.data_type = 3, wdc.data_device_id = ct.stream_proxy_id where wdc.stream_proxy_id is not null; - alter table wvp_device_channel drop stream_proxy_id; - END IF; -END; -call wvp_20241222(); -DROP PROCEDURE wvp_20241222; -/* -* 20241231 -*/ -CREATE PROCEDURE `wvp_20241231`() -BEGIN - IF not EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_stream_proxy' and column_name = 'relates_media_server_id') - THEN - alter table wvp_stream_proxy add relates_media_server_id character varying(50); - END IF; -END; -call wvp_20241231(); -DROP PROCEDURE wvp_20241231; -/* -* 20250111 -*/ -CREATE PROCEDURE `wvp_20250111`() -BEGIN - IF EXISTS (SELECT column_name FROM information_schema.STATISTICS - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_cloud_record' and INDEX_NAME = 'uk_stream_push_app_stream_path') - THEN - alter table wvp_cloud_record drop index uk_stream_push_app_stream_path ; - END IF; - - IF EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_cloud_record' and column_name = 'folder') - THEN - alter table wvp_cloud_record modify folder varchar(500) null; - END IF; - - IF EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_cloud_record' and column_name = 'file_path') - THEN - alter table wvp_cloud_record modify file_path varchar(500) null; - END IF; -END; -call wvp_20250111(); -DROP PROCEDURE wvp_20250111; - -/* -* 20250211 -*/ -CREATE PROCEDURE `wvp_20250211`() -BEGIN - IF EXISTS (SELECT column_name FROM information_schema.STATISTICS - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device' and column_name = 'keepalive_interval_time') - THEN - alter table wvp_device change keepalive_interval_time heart_beat_interval integer after as_message_channel; - END IF; - - IF not EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device' and column_name = 'heart_beat_count') - THEN - alter table wvp_device add heart_beat_count integer; - END IF; - - IF not EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device' and column_name = 'position_capability') - THEN - alter table wvp_device add position_capability integer; - END IF; -END; -call wvp_20250211(); -DROP PROCEDURE wvp_20250211; - -/** - * 20250312 - */ -CREATE PROCEDURE `wvp_20250312`() -BEGIN - DECLARE serverId VARCHAR(32) DEFAULT '你的服务ID'; - IF not EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device' and column_name = 'server_id') - THEN - alter table wvp_device add server_id character varying(50); - update wvp_device set server_id = serverId; - END IF; - - IF not EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_media_server' and column_name = 'server_id') - THEN - alter table wvp_media_server add server_id character varying(50); - update wvp_media_server set server_id = serverId; - END IF; - - IF not EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_stream_proxy' and column_name = 'server_id') - THEN - alter table wvp_stream_proxy add server_id character varying(50); - update wvp_stream_proxy set server_id = serverId; - END IF; - - IF not EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_cloud_record' and column_name = 'server_id') - THEN - alter table wvp_cloud_record add server_id character varying(50); - update wvp_cloud_record set server_id = serverId; - END IF; - - IF not EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_platform' and column_name = 'server_id') - THEN - alter table wvp_platform add server_id character varying(50); - END IF; -END; -call wvp_20250312(); -DROP PROCEDURE wvp_20250312; - -/* -* 20250319 -*/ -CREATE PROCEDURE `wvp_20250319`() -BEGIN - IF NOT EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device_channel' and column_name = 'gps_speed') - THEN - alter table wvp_device_channel add gps_speed double precision; - END IF; - - IF NOT EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device_channel' and column_name = 'gps_altitude') - THEN - alter table wvp_device_channel add gps_altitude double precision; - END IF; - - IF NOT EXISTS (SELECT column_name FROM information_schema.columns - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device_channel' and column_name = 'gps_direction') - THEN - alter table wvp_device_channel add gps_direction double precision; - END IF; -END; -call wvp_20250319(); -DROP PROCEDURE wvp_20250319; - -/* -* 20250402 -*/ -CREATE PROCEDURE `wvp_20250402`() -BEGIN - IF NOT EXISTS (SELECT column_name FROM information_schema.STATISTICS - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device_channel' and INDEX_NAME = 'data_type') - THEN - create index data_type on wvp_device_channel (data_type); - END IF; - IF NOT EXISTS (SELECT column_name FROM information_schema.STATISTICS - WHERE TABLE_SCHEMA = 'wvp' and table_name = 'wvp_device_channel' and INDEX_NAME = 'data_device_id') - THEN - create index data_device_id on wvp_device_channel (data_device_id); - END IF; - -END; -call wvp_20250402(); -DROP PROCEDURE wvp_20250402; - /* * 用户权限配置 */