-
Notifications
You must be signed in to change notification settings - Fork 118
/
create_db.sql
109 lines (97 loc) · 3.21 KB
/
create_db.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
create schema if not exists `sec` collate utf8_general_ci;
use `sec`;
create table if not exists `asset`
(
`id` bigint auto_increment primary key,
`ip` varchar(128) null,
`tags` varchar(256) null,
`region` varchar(64) null,
`ports` longtext null,
`os` longtext null,
`remark` longtext null,
`sub_domain` longtext null,
`dns` longtext null,
`create_time` datetime null,
`modify_time` datetime null
);
create table if not exists `dict`
(
`id` bigint auto_increment primary key,
`dict_key` varchar(256) null,
`dict_value` longtext null,
`remark` varchar(256) null,
`create_time` datetime null,
`modify_time` datetime null
);
create table if not exists `plugin`
(
`id` bigint auto_increment primary key,
`title` varchar(256) null,
`remark` longtext null,
`publisher` varchar(128) null,
`script` varchar(256) null,
`label` varchar(64) null,
`hide` int(1) default 0 null,
`create_time` datetime null,
`modify_time` datetime null
);
create table if not exists `task`
(
`id` bigint auto_increment primary key,
`task_name` varchar(256) null,
`script` varchar(265) null,
`script_name` varchar(256) null,
`target` varchar(128) null,
`state` varchar(65) null,
`cron` varchar(64) null,
`result` longtext null,
`result_state` tinyint(1) null,
`handle_state` varchar(64) null,
`handle_node` varchar(256) null,
`create_time` datetime null,
`modify_time` datetime null
);
create table if not exists `user`
(
`id` bigint auto_increment primary key,
`user_name` varchar(64) null,
`pass_word` varchar(128) null,
`salt` varchar(128) null,
`state` varchar(64) null,
`type` varchar(64) null,
`create_time` datetime null,
`modify_time` datetime null
);
alter table sec.asset
convert to character set utf8;
alter table sec.plugin
convert to character set utf8;
alter table sec.task
convert to character set utf8;
ALTER TABLE sec.asset
DEFAULT CHARACTER SET utf8;
ALTER TABLE sec.plugin
DEFAULT CHARACTER SET utf8;
ALTER TABLE sec.task
DEFAULT CHARACTER SET utf8;
DROP PROCEDURE IF EXISTS pro_AddColumn;
DELIMITER //
CREATE PROCEDURE pro_AddColumn()
BEGIN
IF NOT EXISTS(SELECT 1 FROM information_schema.columns WHERE table_name = 'asset' AND COLUMN_NAME = 'remark') THEN
alter table sec.asset
add remark longtext null after os;
END IF;
IF NOT EXISTS(
SELECT 1 FROM information_schema.columns WHERE table_name = 'asset' AND COLUMN_NAME = 'sub_domain') THEN
alter table sec.asset
add sub_domain longtext null after remark;
END IF;
IF NOT EXISTS(SELECT 1 FROM information_schema.columns WHERE table_name = 'asset' AND COLUMN_NAME = 'dns') THEN
alter table sec.asset
add dns longtext null after sub_domain;
END IF;
END//
DELIMITER ;
CALL pro_AddColumn;
DROP PROCEDURE pro_AddColumn;