-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
170 lines (156 loc) · 4.77 KB
/
schema.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
create table if not exists medals
(
idMedal bigint unsigned not null
primary key,
idUnit bigint unsigned not null,
weight smallint default 0 not null,
name varchar(64) not null,
image text null,
dateCreated datetime default CURRENT_TIMESTAMP not null,
dateUpdated datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP
);
create table if not exists members_endorsements
(
idMemberEndorsement int unsigned auto_increment
primary key,
idMember bigint unsigned null,
idEndorsement bigint unsigned null,
dateCreated datetime null,
dateUpdated datetime null
);
create table if not exists members_medals
(
idMemberMedal int unsigned auto_increment
primary key,
idMember bigint unsigned not null,
idMedal bigint unsigned not null,
remarks text null,
dateAwarded datetime not null,
dateCreated datetime default CURRENT_TIMESTAMP not null,
dateUpdated datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP
);
create table if not exists operations
(
idOp bigint unsigned not null
primary key,
idUnit bigint unsigned not null,
dateOp datetime not null,
name varchar(64) default '' not null,
remarks text null,
remarksInternal text null,
dateCreated datetime default CURRENT_TIMESTAMP not null,
dateUpdated datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP
);
create table if not exists ranks
(
idRank bigint unsigned not null
primary key,
idUnit bigint unsigned not null,
weight smallint default 0 not null,
abbr varchar(16) not null,
name varchar(64) not null,
icon text null,
dateCreated datetime default CURRENT_TIMESTAMP not null,
dateUpdated datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP
);
create table if not exists sessions
(
idSession varchar(64) not null
primary key,
data text not null,
ip binary(16) null,
userAgent varchar(255) null,
idUser bigint unsigned null,
dateCreated datetime default CURRENT_TIMESTAMP not null,
dateUpdated datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP
);
create index sessions_idUser_index
on sessions (idUser);
create table if not exists squads
(
idGroup bigint unsigned not null
primary key,
idUnit bigint unsigned not null,
idParent bigint unsigned null,
weight smallint default 0 not null,
name varchar(64) not null,
color char(7) null,
dateCreated datetime default CURRENT_TIMESTAMP not null,
dateUpdated datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP
);
create table if not exists units
(
idUnit bigint unsigned not null
primary key,
name varchar(64) not null,
slug varchar(32) null,
icon mediumtext null,
dateCreated datetime default CURRENT_TIMESTAMP not null,
dateUpdated datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP,
constraint slug
unique (slug)
);
create table if not exists endorsements
(
idEndorsement bigint unsigned not null
primary key,
idUnit bigint unsigned null,
weight smallint null,
abbr varchar(16) null,
name varchar(64) null,
dateCreated datetime null,
dateUpdated datetime null,
constraint endorsements_units_idUnit_fk
foreign key (idUnit) references units (idUnit)
on delete cascade
);
create table if not exists members
(
idMember bigint unsigned not null
primary key,
idUnit bigint unsigned not null,
idRank bigint unsigned not null,
idGroup bigint unsigned null,
name varchar(64) not null,
playerName varchar(64) default '' not null,
role varchar(64) default '' not null,
dateJoined date null,
dateLastPromotion date null,
remarks text null,
remarksInternal text null,
dateCreated datetime default CURRENT_TIMESTAMP not null,
dateUpdated datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP,
constraint members_ranks_idRank_fk
foreign key (idRank) references ranks (idRank),
constraint members_squads_idGroup_fk
foreign key (idGroup) references squads (idGroup)
on delete set null,
constraint members_units_idUnit_fk
foreign key (idUnit) references units (idUnit)
on delete cascade
);
create table if not exists units_editors
(
idUnitEditor int unsigned auto_increment
primary key,
idUnit bigint unsigned not null,
idUser bigint unsigned not null,
dateCreated datetime default CURRENT_TIMESTAMP not null,
dateUpdated datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP
);
create table if not exists users
(
idUser bigint unsigned not null
primary key,
username varchar(64) not null,
displayName varchar(64) null,
avatar varchar(64) null,
banner varchar(64) null,
dateCreated datetime default CURRENT_TIMESTAMP not null,
dateUpdated datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP,
isAdmin tinyint(1) default 0 not null,
isMod tinyint(1) default 0 not null,
isBanned tinyint(1) default 0 not null,
constraint username_UNIQUE
unique (username)
);