-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vote.sql
175 lines (137 loc) · 4.77 KB
/
Vote.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
DROP DATABASE IF EXISTS vote_db;
CREATE DATABASE vote_db;
USE vote_db;
CREATE TABLE users(
id int NOT NULL AUTO_INCREMENT,
email VARCHAR(255) NOT NULL,
username VARCHAR(30) NOT NULL,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
token VARCHAR(255) NOT NULL,
perms INT NOT NULL DEFAULT 0,
journalist BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (id),
UNIQUE (email),
UNIQUE (username)
);
CREATE TABLE parties(
id int NOT NULL AUTO_INCREMENT,
label VARCHAR(6) NOT NULL,
name VARCHAR(255) NOT NULL,
logo VARCHAR(255),
ideology int NOT NULL,
color VARCHAR(255) NOT NULL,
leader int,
PRIMARY KEY (id),
UNIQUE (label),
UNIQUE (leader),
FOREIGN KEY (leader) REFERENCES users(id)
);
CREATE TABLE users_parties(
id int NOT NULL AUTO_INCREMENT,
user_id int NOT NULL,
party_id int NOT NULL,
PRIMARY KEY (id),
UNIQUE (user_id),
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (party_id) REFERENCES parties(id)
);
CREATE TABLE party_join_requests(
id int NOT NULL AUTO_INCREMENT,
user_id int NOT NULL,
party_id int NOT NULL,
status VARCHAR(255) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (party_id) REFERENCES parties(id)
);
CREATE TABLE laws(
id int NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
status VARCHAR(255) NOT NULL,
party_id int NOT NULL,
user_id int,
law_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
sign VARCHAR(255),
PRIMARY KEY (id),
FOREIGN KEY (party_id) REFERENCES parties(id),
FOREIGN KEY (user_id) REFERENCES users(id),
UNIQUE (title)
);
CREATE TABLE articles(
id int NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
law_id int NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (law_id) REFERENCES laws(id)
);
CREATE TABLE sessions(
id int NOT NULL AUTO_INCREMENT,
user_id int NOT NULL,
title VARCHAR(255) NOT NULL,
type VARCHAR(255) NOT NULL,
session_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
target_id int,
value varchar(255),
completed BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (id),
UNIQUE(type, target_id),
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE government_members(
id int NOT NULL AUTO_INCREMENT,
role VARCHAR(255) NOT NULL,
perms INT NOT NULL DEFAULT 0,
user_id int,
depends_of int,
PRIMARY KEY (id),
UNIQUE (role),
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (depends_of) REFERENCES government_members(id)
);
CREATE TABLE news(
id int NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
subtitle VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
author VARCHAR(255) NOT NULL,
type VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE mails(
id int NOT NULL AUTO_INCREMENT,
sender_id int NOT NULL,
receiver_id int NOT NULL,
subject VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
mail_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
status VARCHAR(255) NOT NULL,
type VARCHAR(255) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (sender_id) REFERENCES users(id),
FOREIGN KEY (receiver_id) REFERENCES users(id)
);
CREATE TABLE rules(
id int NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
value int NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO rules (name, value) VALUES ('Puntos a la semana', 20);
INSERT INTO rules (name, value) VALUES ('Infraccion menor', -10);
INSERT INTO rules (name, value) VALUES ('Intraccion mayor', -20);
INSERT INTO parties (label, name, logo, ideology, color) VALUES ('IND', 'Independiente', '', 0, '#6a6a6a');
-- Insertar la constitución en la tabla `laws`
INSERT INTO laws (title, description, status, party_id, sign) VALUES
('Constitución', 'Constitución de la Clase', 'signed', 1, 'Xavier Foster');
SET @law_id = LAST_INSERT_ID();
-- Insertar algunos artículos más desarrollados en la tabla `articles`
INSERT INTO articles (title, content, law_id) VALUES
('Artículo 1', 'El artículo 1 establece los derechos y libertades fundamentales de los ciudadanos, incluyendo la libertad de expresión, religión y reunión.', @law_id),
('Artículo 2', 'El artículo 2 define la estructura del gobierno, incluyendo el poder ejecutivo, legislativo y judicial, y sus respectivas funciones y responsabilidades.', @law_id),
('Artículo 3', 'El artículo 3 describe el proceso de enmienda de la constitución, permitiendo cambios y actualizaciones a través de un procedimiento legislativo específico.', @law_id);
INSERT INTO government_members (role, user_id, perms) VALUES ('Presidente', NULL, 8);