-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql.create.trigger.txt
executable file
·219 lines (146 loc) · 7.43 KB
/
sql.create.trigger.txt
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
DELIMITER $$
DROP TRIGGER IF EXISTS `by_update_setting_revision` $$
CREATE TRIGGER by_update_setting_revision AFTER UPDATE ON tb_setting
FOR EACH ROW
BEGIN
IF OLD.value != NEW.value THEN
INSERT INTO tb_setting_revision (setting_idx, parameter, value, exec_user_idx, timestamp, client_ip)
VALUES (OLD.idx, OLD.parameter, NEW.value, NEW.exec_user_idx, UNIX_TIMESTAMP(NOW()), NEW.client_ip);
END IF;
END;
$$
DROP TRIGGER IF EXISTS `by_insert_setting_revision` $$
CREATE TRIGGER by_insert_setting_revision AFTER INSERT ON tb_setting
FOR EACH ROW
BEGIN
INSERT INTO tb_setting_revision (setting_idx, parameter, value, exec_user_idx, timestamp, client_ip)
VALUES (NEW.idx, NEW.parameter, NEW.value, NEW.exec_user_idx, UNIX_TIMESTAMP(NOW()), NEW.client_ip);
END;
$$
DELIMITER ;
DELIMITER $$
DROP TRIGGER IF EXISTS `by_insert_bbs_setting_revision` $$
CREATE TRIGGER by_insert_bbs_setting_revision AFTER INSERT ON tb_bbs_setting
FOR EACH ROW
BEGIN
INSERT INTO tb_bbs_setting_revision (bbs_idx, setting_idx, parameter, value, exec_user_idx, timestamp, client_ip)
VALUES (NEW.bbs_idx, NEW.idx, NEW.parameter, NEW.value, NEW.exec_user_idx, UNIX_TIMESTAMP(NOW()), NEW.client_ip);
END;
$$
DROP TRIGGER IF EXISTS `by_update_bbs_setting_revision` $$
CREATE TRIGGER by_update_bbs_setting_revision AFTER UPDATE ON tb_bbs_setting
FOR EACH ROW
BEGIN
IF OLD.value != NEW.value THEN
INSERT INTO tb_bbs_setting_revision (bbs_idx, setting_idx, parameter, value, exec_user_idx, timestamp, client_ip)
VALUES (OLD.bbs_idx, OLD.idx, OLD.parameter, NEW.value, NEW.exec_user_idx, UNIX_TIMESTAMP(NOW()), NEW.client_ip);
END IF;
END;
$$
DELIMITER ;
DELIMITER $$
DROP TRIGGER IF EXISTS `by_insert_bbs_category_revision` $$
CREATE TRIGGER by_insert_bbs_category_revision AFTER INSERT ON tb_bbs_category
FOR EACH ROW
BEGIN
INSERT INTO tb_bbs_category_revision (bbs_idx, category_idx, category_name, sequence, exec_user_idx, timestamp, client_ip, is_used)
VALUES (NEW.bbs_idx, NEW.idx, NEW.category_name, sequence, NEW.exec_user_idx, UNIX_TIMESTAMP(NOW()), NEW.client_ip, NEW.is_used);
END;
$$
DROP TRIGGER IF EXISTS `by_update_bbs_category_revision` $$
CREATE TRIGGER by_update_bbs_category_revision AFTER UPDATE ON tb_bbs_category
FOR EACH ROW
BEGIN
IF OLD.category_name != NEW.category_name OR OLD.is_used != NEW.is_used OR OLD.sequence != NEW.sequence THEN
INSERT INTO tb_bbs_category_revision (bbs_idx, category_idx, category_name, sequence, exec_user_idx, timestamp, client_ip, is_used)
VALUES (OLD.bbs_idx, OLD.idx, NEW.category_name, NEW.sequence, NEW.exec_user_idx, UNIX_TIMESTAMP(NOW()), NEW.client_ip, NEW.is_used);
END IF;
END;
$$
DELIMITER ;
DELIMITER $$
DROP TRIGGER IF EXISTS `by_insert_users_group_revision` $$
CREATE TRIGGER by_insert_users_group_revision AFTER INSERT ON tb_users_group
FOR EACH ROW
BEGIN
INSERT INTO tb_users_group_revision (group_idx, group_name, icon_path, exec_user_idx, timestamp, client_ip, is_used)
VALUES (NEW.idx, NEW.group_name, NEW.icon_path, NEW.exec_user_idx, UNIX_TIMESTAMP(NOW()), NEW.client_ip, NEW.is_used);
END;
$$
DROP TRIGGER IF EXISTS `by_update_users_group_revision` $$
CREATE TRIGGER by_update_users_group_revision AFTER UPDATE ON tb_users_group
FOR EACH ROW
BEGIN
IF OLD.group_name != NEW.group_name OR OLD.icon_path != NEW.icon_path OR OLD.is_used != NEW.is_used THEN
INSERT INTO tb_users_group_revision (group_idx, group_name, icon_path, exec_user_idx, timestamp, client_ip, is_used)
VALUES (OLD.idx, NEW.group_name, NEW.icon_path, NEW.exec_user_idx, UNIX_TIMESTAMP(NOW()), NEW.client_ip, NEW.is_used);
END IF;
END;
$$
DELIMITER ;
DELIMITER $$
DROP TRIGGER IF EXISTS `by_insert_bbs_article_revision` $$
CREATE TRIGGER by_insert_bbs_article_revision AFTER INSERT ON tb_bbs_article
FOR EACH ROW
BEGIN
INSERT INTO tb_bbs_article_revision (bbs_idx, article_idx, category_idx, exec_user_idx, title, timestamp, client_ip, is_notice, is_secret, is_deleted)
VALUES (NEW.bbs_idx, NEW.idx, NEW.category_idx, NEW.exec_user_idx, NEW.title, UNIX_TIMESTAMP(NOW()), NEW.client_ip_insert, NEW.is_notice, NEW.is_secret, NEW.is_deleted);
END;
$$
DROP TRIGGER IF EXISTS `by_update_bbs_article_revision` $$
CREATE TRIGGER by_update_bbs_article_revision AFTER UPDATE ON tb_bbs_article
FOR EACH ROW
BEGIN
IF OLD.bbs_idx != NEW.bbs_idx OR OLD.category_idx != NEW.category_idx OR OLD.title != NEW.title OR OLD.is_notice != NEW.is_notice OR OLD.is_secret != NEW.is_secret OR OLD.is_deleted != NEW.is_deleted THEN
INSERT INTO tb_bbs_article_revision (bbs_idx, article_idx, category_idx, exec_user_idx, title, timestamp, client_ip, is_notice, is_secret, is_deleted)
VALUES (NEW.bbs_idx, OLD.idx, NEW.category_idx, NEW.exec_user_idx, NEW.title, UNIX_TIMESTAMP(NOW()), NEW.client_ip_update, NEW.is_notice, NEW.is_secret, NEW.is_deleted);
END IF;
END;
$$
DELIMITER ;
DELIMITER $$
DROP TRIGGER IF EXISTS `by_insert_bbs_contents_revision` $$
CREATE TRIGGER by_insert_bbs_contents_revision AFTER INSERT ON tb_bbs_contents
FOR EACH ROW
BEGIN
INSERT INTO tb_bbs_contents_revision (bbs_idx, article_idx, contents_idx, exec_user_idx, contents, timestamp, client_ip)
VALUES (NEW.bbs_idx, NEW.article_idx, NEW.idx, NEW.exec_user_idx, NEW.contents, UNIX_TIMESTAMP(NOW()), NEW.client_ip);
END;
$$
DROP TRIGGER IF EXISTS `by_update_bbs_contents_revision` $$
CREATE TRIGGER by_update_bbs_contents_revision AFTER UPDATE ON tb_bbs_contents
FOR EACH ROW
BEGIN
IF OLD.bbs_idx != NEW.bbs_idx OR OLD.contents != NEW.contents THEN
INSERT INTO tb_bbs_contents_revision (bbs_idx, article_idx, contents_idx, exec_user_idx, contents, timestamp, client_ip)
VALUES (NEW.bbs_idx, OLD.article_idx, OLD.idx, NEW.exec_user_idx, NEW.contents, UNIX_TIMESTAMP(NOW()), NEW.client_ip);
END IF;
END;
$$
DELIMITER ;
DELIMITER $$
DROP TRIGGER IF EXISTS `by_insert_bbs_comment_revision` $$
CREATE TRIGGER by_insert_bbs_comment_revision AFTER INSERT ON tb_bbs_comment
FOR EACH ROW
BEGIN
INSERT INTO tb_bbs_comment_revision (bbs_idx, article_idx, comment_idx, exec_user_idx, comment, timestamp, client_ip, is_deleted)
VALUES (NEW.bbs_idx, NEW.article_idx, NEW.idx, NEW.exec_user_idx, NEW.comment, UNIX_TIMESTAMP(NOW()), NEW.client_ip_insert, NEW.is_deleted);
END;
$$
DROP TRIGGER IF EXISTS `by_update_bbs_comment_revision` $$
CREATE TRIGGER by_update_bbs_comment_revision AFTER UPDATE ON tb_bbs_comment
FOR EACH ROW
BEGIN
IF OLD.bbs_idx != NEW.bbs_idx OR OLD.comment != NEW.comment OR OLD.is_deleted != NEW.is_deleted THEN
INSERT INTO tb_bbs_comment_revision (bbs_idx, article_idx, comment_idx, exec_user_idx, comment, timestamp, client_ip, is_deleted)
VALUES (NEW.bbs_idx, OLD.article_idx, OLD.idx, NEW.exec_user_idx, NEW.comment, UNIX_TIMESTAMP(NOW()), NEW.client_ip_update, NEW.is_deleted);
END IF;
END;
$$
DELIMITER ;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;