· 8 years ago · Apr 11, 2018, 12:00 AM
1 1 -- vim: nu: tabstop=4: softtabstop=4: shiftwidth=4: expandtab
2 2 DROP DATABASE IF EXISTS state;
3 3 CREATE DATABASE state;
4 4 USE state;
5 5
6 6 DROP TABLE IF EXISTS stategroup;
7 7 CREATE TABLE stategroup (
8 8 id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT
9 9 , name VARCHAR(32) NOT NULL
10 10 , desciption VARCHAR(128) NOT NULL DEFAULT '--'
11 11 , created_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
12 12 , updated_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
13 13 , is_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0
14 14 , PRIMARY KEY(id)
15 15 ) ENGINE=InnoDB;
16 16
17 17 DROP TABLE IF EXISTS stategroup_to_stategroup_link;
18 18 CREATE TABLE stategroup_to_stategroup_link (
19 19 id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT
20 20 , parent_id INT(10) UNSIGNED NOT NULL
21 21 , child_id INT(10) UNSIGNED NOT NULL
22 22 , created_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
23 23 , updated_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
24 24 , is_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0
25 25 , PRIMARY KEY(id)
26 26 , FOREIGN KEY(parent_id) REFERENCES stategroup(id)
27 27 , FOREIGN KEY(child_id) REFERENCES stategroup(id)
28 28 ) ENGINE=InnoDB;
29 29
30 30 DROP TABLE IF EXISTS state;
31 31 CREATE TABLE state (
32 32 id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT
33 33 , name VARCHAR(32) NOT NULL
34 34 , desciption VARCHAR(128) NOT NULL DEFAULT '--'
35 35 , value TINYINT(1) NOT NULL DEFAULT -1
36 36 , created_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
37 37 , updated_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
38 38 , is_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0
39 39 , stategroup_id INT(10) UNSIGNED NOT NULL
40 40 , PRIMARY KEY(id)
41 41 , FOREIGN KEY(stategroup_id) REFERENCES stategroup(id)
42 42 ) ENGINE=InnoDB;
43 43