Assembla home | Assembla project page
 

WikiStart: database-design-0.1.sql

File database-design-0.1.sql, 5.9 kB (added by Vincent, 2 years ago)

Database tables (SQL)

Line 
1 -- ------------------------------------------------------------
2 -- Lots of account information.
3 -- ------------------------------------------------------------
4
5 CREATE TABLE accounts (
6   user_id INTEGER UNSIGNED NOT NULL,
7   username VARCHAR(255) NOT NULL,
8   password VARCHAR(40) NOT NULL,
9   salt INTEGER(4) NOT NULL,
10   type ENUM('client','employee','admin') NOT NULL,
11   sex ENUM('m' , 'f') NOT NULL,
12   first_name VARCHAR(45) NOT NULL,
13   prefix VARCHAR(10) NULL,
14   last_name VARCHAR(45) NOT NULL,
15   street VARCHAR(50) NULL,
16   nr VARCHAR(10) NULL,
17   city VARCHAR(20) NULL,
18   zipcode VARCHAR(6) NULL,
19   email VARCHAR(255) NULL,
20   PRIMARY KEY(user_id)
21 );
22
23 -- ------------------------------------------------------------
24 -- Account related setting. Stores settings as an association between the setting name and user_id (not as a single user_id with a given number of settings). This allows for a variable number of settings, so the database structure won't have to change often.
25 -- ------------------------------------------------------------
26
27 CREATE TABLE account_settings (
28   user_id INTEGER UNSIGNED NOT NULL,
29   setting_name VARCHAR(20) NOT NULL,
30   value VARCHAR(255) NULL,
31   PRIMARY KEY(user_id, setting_name)
32 );
33
34 -- ------------------------------------------------------------
35 -- This table associates certain users (with type ' client' ) with students.
36 -- ------------------------------------------------------------
37
38 CREATE TABLE client_student_junction (
39   client_id INTEGER UNSIGNED NOT NULL,
40   student_id INTEGER UNSIGNED NOT NULL,
41   PRIMARY KEY(client_id, student_id)
42 );
43
44 -- ------------------------------------------------------------
45 -- This table can be used to store all kinds of settings and preferences, because we should only use a flat file for basic, one-time settings.
46 -- ------------------------------------------------------------
47
48 CREATE TABLE configuration (
49   setting_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
50   name VARCHAR(20) NULL,
51   value VARCHAR(255) NULL,
52   PRIMARY KEY(setting_id)
53 );
54
55 -- ------------------------------------------------------------
56 -- This table associates certain users (with type 'employee') with the groups they belong to.
57 -- ------------------------------------------------------------
58
59 CREATE TABLE employee_group_junction (
60   employee_id INTEGER UNSIGNED NOT NULL,
61   group_id INTEGER UNSIGNED NOT NULL,
62   PRIMARY KEY(employee_id, group_id)
63 );
64
65 -- ------------------------------------------------------------
66 -- Links employees with the meetings that they can attend.
67 -- ------------------------------------------------------------
68
69 CREATE TABLE employee_meetings (
70   employee_id INTEGER UNSIGNED NOT NULL,
71   meeting_id INTEGER UNSIGNED NOT NULL,
72   PRIMARY KEY(employee_id, meeting_id)
73 );
74
75 -- ------------------------------------------------------------
76 -- Event information.
77 -- ------------------------------------------------------------
78
79 CREATE TABLE events (
80   event_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
81   friendly_name VARCHAR(45) NOT NULL,
82   tag VARCHAR(45) NOT NULL,
83   event_status ENUM('planning','employees','clients','closed','done') NOT NULL,
84   notify_employees DATETIME NOT NULL,
85   notify_clients DATETIME NOT NULL,
86   close_date DATETIME NOT NULL,
87   PRIMARY KEY(event_id)
88 );
89
90 -- ------------------------------------------------------------
91 -- Associates events with their relevant groups.
92 -- ------------------------------------------------------------
93
94 CREATE TABLE event_group_junction (
95   group_id INTEGER UNSIGNED NOT NULL,
96   event_id INTEGER UNSIGNED NOT NULL,
97   PRIMARY KEY(group_id, event_id)
98 );
99
100 -- ------------------------------------------------------------
101 -- Information about groups.
102 -- ------------------------------------------------------------
103
104 CREATE TABLE groups (
105   group_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
106   friendly_name VARCHAR(45) NOT NULL,
107   tag VARCHAR(45) NOT NULL,
108   priority TINYINT UNSIGNED NOT NULL,
109   PRIMARY KEY(group_id)
110 );
111
112 -- ------------------------------------------------------------
113 -- Events are made up of several meetings. This table stores information about meetings.
114 -- ------------------------------------------------------------
115
116 CREATE TABLE meetings (
117   meeting_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
118   event_id INTEGER UNSIGNED NOT NULL,
119   start_time DATETIME NULL,
120   slot_duration TIME NULL,
121   slots INTEGER UNSIGNED NULL,
122   PRIMARY KEY(meeting_id)
123 );
124
125 -- ------------------------------------------------------------
126 -- Basic information about students. Note that students are not users and can therefore not login.
127 -- The only information we require at the moment is the studentnumber (the student_id column is there to provide a uniform way to link other tables).
128 -- ------------------------------------------------------------
129
130 CREATE TABLE students (
131   student_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
132   student_tag VARCHAR(20) NOT NULL,
133   name VARCHAR(255) NULL,
134   PRIMARY KEY(student_id)
135 );
136
137 -- ------------------------------------------------------------
138 -- Associates students with a certain group.
139 -- ------------------------------------------------------------
140
141 CREATE TABLE student_group_junction (
142   group_id INTEGER UNSIGNED NOT NULL,
143   student_id INTEGER UNSIGNED NOT NULL,
144   PRIMARY KEY(group_id, student_id)
145 );
146
147 -- ------------------------------------------------------------
148 -- Keeps track of user choices regarding 'who' and 'when'.
149 -- After the close_date of an event (that is when the schedule is being created), the 'choices' will be replaced by the actual data (this will probably only involve setting the slot number, which can't be chosen by the user anyway).
150 -- ------------------------------------------------------------
151
152 CREATE TABLE student_meetings (
153   meeting_id INTEGER UNSIGNED NOT NULL,
154   student_id INTEGER UNSIGNED NOT NULL,
155   employee_id INTEGER UNSIGNED NOT NULL,
156   slot INTEGER UNSIGNED NULL,
157   PRIMARY KEY(meeting_id, student_id)
158 );
159
160