-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcorona_properties.sql
executable file
·160 lines (139 loc) · 5.67 KB
/
corona_properties.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
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
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='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema cpdb
-- -----------------------------------------------------
DROP SCHEMA IF EXISTS `cpdb` ;
-- -----------------------------------------------------
-- Schema cpdb
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `cpdb` DEFAULT CHARACTER SET utf8mb4 ;
USE `cpdb` ;
-- -----------------------------------------------------
-- Table `cpdb`.`activity_audit`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `cpdb`.`activity_audit` ;
CREATE TABLE IF NOT EXISTS `cpdb`.`activity_audit` (
`action_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` BIGINT UNSIGNED NULL DEFAULT NULL,
`fName` VARCHAR(60) NULL DEFAULT NULL,
`lName` VARCHAR(60) NULL DEFAULT NULL,
`email` VARCHAR(60) NULL DEFAULT NULL,
`action_type` VARCHAR(10) NOT NULL,
`action_timestamp` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY (`action_id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4;
-- -----------------------------------------------------
-- Table `cpdb`.`deleted_data`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `cpdb`.`deleted_data` ;
CREATE TABLE IF NOT EXISTS `cpdb`.`deleted_data` (
`deleted_data_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`propertyPrimaryKey` BIGINT UNSIGNED NULL DEFAULT NULL,
`propertyType` VARCHAR(8) NOT NULL,
`addressNum` VARCHAR(7) NOT NULL,
`addressStreet` VARCHAR(50) NOT NULL,
`addressCity` VARCHAR(60) NOT NULL,
`addressCode` VARCHAR(7) NOT NULL,
`value` DOUBLE UNSIGNED NOT NULL,
`constructionStatus` VARCHAR(11) NOT NULL,
`useOfProperty` VARCHAR(15) NOT NULL,
`room` TINYINT(3) UNSIGNED NOT NULL,
`garage` TINYINT(3) UNSIGNED NOT NULL,
`bath` TINYINT(3) UNSIGNED NOT NULL,
`floorArea` DOUBLE UNSIGNED NOT NULL,
`landArea` DOUBLE UNSIGNED NOT NULL,
`rates` DOUBLE UNSIGNED NOT NULL,
`description` TEXT NOT NULL,
`telephone` VARCHAR(10) NOT NULL,
`email` VARCHAR(60) NOT NULL,
`deleted_timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY (`deleted_data_id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4;
-- -----------------------------------------------------
-- Table `cpdb`.`property`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `cpdb`.`property` ;
CREATE TABLE IF NOT EXISTS `cpdb`.`property` (
`propertyPrimaryKey` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`propertyType` VARCHAR(8) NOT NULL,
`addressNum` VARCHAR(5) NOT NULL,
`addressStreet` VARCHAR(50) NOT NULL,
`addressCity` VARCHAR(60) NOT NULL,
`addressCode` VARCHAR(7) NOT NULL,
`value` DOUBLE UNSIGNED NOT NULL,
`constructionStatus` VARCHAR(11) NOT NULL,
`useOfProperty` VARCHAR(15) NOT NULL,
`room` TINYINT(3) UNSIGNED NOT NULL,
`garage` TINYINT(3) UNSIGNED NOT NULL,
`bath` TINYINT(3) UNSIGNED NOT NULL,
`floorArea` DOUBLE UNSIGNED NOT NULL,
`landArea` DOUBLE UNSIGNED NOT NULL,
`rates` DOUBLE UNSIGNED NOT NULL,
`description` TEXT NOT NULL,
`telephone` VARCHAR(10) NOT NULL,
`email` VARCHAR(60) NOT NULL,
PRIMARY KEY (`propertyPrimaryKey`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4;
-- -----------------------------------------------------
-- Table `cpdb`.`user`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `cpdb`.`user` ;
CREATE TABLE IF NOT EXISTS `cpdb`.`user` (
`user_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`fName` VARCHAR(60) NOT NULL,
`lName` VARCHAR(60) NOT NULL,
`email` VARCHAR(60) NOT NULL,
`password` VARCHAR(200) NOT NULL,
`action` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (`user_id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
USE `cpdb`;
DELIMITER $$
USE `cpdb`$$
DROP TRIGGER IF EXISTS `cpdb`.`before_data_delete` $$
USE `cpdb`$$
CREATE
TRIGGER `cpdb`.`before_data_delete`
BEFORE DELETE ON `cpdb`.`property`
FOR EACH ROW
BEGIN
INSERT INTO deleted_data
VALUES(null, OLD.propertyPrimaryKey,OLD.propertyType,OLD.addressNum, OLD.addressStreet, OLD.addressCity, OLD.addressCode, OLD.value, OLD.constructionStatus, OLD.useOfProperty, OLD.room, OLD.garage, OLD.bath, OLD.floorArea, OLD.landArea, OLD.rates, OLD.description, OLD.telephone, OLD.email, NOW());
END$$
USE `cpdb`$$
DROP TRIGGER IF EXISTS `cpdb`.`user_after_crud` $$
USE `cpdb`$$
CREATE
TRIGGER `cpdb`.`user_after_crud`
AFTER UPDATE ON `cpdb`.`user`
FOR EACH ROW
BEGIN
IF (NEW.action = '1') THEN
INSERT INTO activity_audit VALUES(null, NEW.user_id, NEW.fName, NEW.lName, NEW.email, 'SIGN IN' ,NOW());
END IF;
IF (NEW.action = '2') THEN
INSERT INTO activity_audit VALUES(null, NEW.user_id, NEW.fName, NEW.lName, NEW.email, 'SIGN OUT' ,NOW());
END IF;
IF (NEW.action = '3') THEN
INSERT INTO activity_audit VALUES(null, NEW.user_id, NEW.fName, NEW.lName, NEW.email, 'NEW' ,NOW());
END IF;
IF (NEW.action = '4') THEN
INSERT INTO activity_audit VALUES(null, NEW.user_id, NEW.fName, NEW.lName, NEW.email, 'UPDATE' ,NOW());
END IF;
IF (NEW.action = '5') THEN
INSERT INTO activity_audit VALUES(null, NEW.user_id, NEW.fName, NEW.lName, NEW.email, 'DELETE' ,NOW());
END IF;
END$$
DELIMITER ;