-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.sql
105 lines (94 loc) · 2.97 KB
/
database.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
CREATE TYPE article_status AS ENUM ('Draft', 'Pending', 'Private', 'Publish', 'Trash');
CREATE TABLE t_article (
id VARCHAR(8) PRIMARY KEY,
content TEXT,
"status" article_status DEFAULT 'Draft',
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ
);
CREATE TABLE t_article_props (
id VARCHAR(8) PRIMARY KEY,
article_id VARCHAR(8) NOT NULL REFERENCES t_article (id),
"name" VARCHAR(30) NOT NULL,
"value" VARCHAR(150) NOT NULL,
sortkey INTEGER NOT NULL
);
CREATE TABLE t_states (
id VARCHAR(8) PRIMARY KEY,
article_id VARCHAR(8) REFERENCES t_article (id),
"name" VARCHAR(50) NOT NULL,
uf VARCHAR(2) NOT NULL,
latitude NUMERIC NOT NULL,
longitude NUMERIC NOT NULL
);
CREATE TABLE t_cities (
id VARCHAR(8) PRIMARY KEY,
state_id VARCHAR(8) NOT NULL REFERENCES t_states (id),
article_id VARCHAR(8) REFERENCES t_article (id),
city VARCHAR(100) NOT NULL,
slug VARCHAR(100) NOT NULL,
abbreviation VARCHAR(4) NOT NULL,
border_towns_id TEXT[],
latitude NUMERIC NOT NULL,
longitude NUMERIC NOT NULL
);
CREATE TABLE t_children (
id VARCHAR(8) PRIMARY KEY,
city_id VARCHAR(8) NOT NULL REFERENCES t_cities (id),
article_id VARCHAR(8) REFERENCES t_article (id),
"name" VARCHAR(100) NOT NULL,
"url" VARCHAR,
short_desc VARCHAR(100) NOT NULL,
biography TEXT,
date_birth DATE,
date_death DATE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ
);
CREATE TYPE municipal_region_type AS ENUM ('Neighborhood', 'Village', 'District');
CREATE TABLE t_municipal_regions (
id VARCHAR(8) PRIMARY KEY,
city_id VARCHAR(8) NOT NULL REFERENCES t_cities (id),
article_id VARCHAR(8) REFERENCES t_article (id),
"name" VARCHAR(150) NOT NULL,
region municipal_region_type NOT NULL DEFAULT 'Neighborhood',
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ
);
CREATE TABLE t_municipal_regions_props (
id VARCHAR(8) PRIMARY KEY,
municipal_regions_id VARCHAR(8) NOT NULL REFERENCES t_municipal_regions (id),
"name" VARCHAR(30) NOT NULL,
"value" VARCHAR(150) NOT NULL,
sortkey INTEGER NOT NULL
);
CREATE TABLE t_address (
id VARCHAR(8) PRIMARY KEY,
city_id VARCHAR(8) NOT NULL REFERENCES t_cities (id),
municipal_regions_id VARCHAR(8) NOT NULL REFERENCES t_municipal_regions (id),
article_id VARCHAR(8) REFERENCES t_article (id),
"name" VARCHAR(150) NOT NULL,
"number" VARCHAR,
complement VARCHAR(150),
zip_code INTEGER,
latitude NUMERIC NOT NULL,
longitude NUMERIC NOT NULL
);
CREATE TABLE t_attractions (
id VARCHAR(8) PRIMARY KEY,
address_id VARCHAR(8) NOT NULL REFERENCES t_address (id),
article_id VARCHAR(8) REFERENCES t_article (id),
"name" VARCHAR NOT NULL,
"short_desc" VARCHAR(150) NOT NULL,
activity TEXT[] NOT NULL,
"site" VARCHAR(100),
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ
);
CREATE TABLE t_attractions_props (
id VARCHAR(8) PRIMARY KEY,
attractions_id VARCHAR(8) NOT NULL REFERENCES t_attractions (id),
"name" VARCHAR(30) NOT NULL,
"value" VARCHAR(150) NOT NULL,
sortkey INTEGER NOT NULL
);