aboutsummaryrefslogtreecommitdiff
path: root/migrations
diff options
context:
space:
mode:
authorNathan Ringo <nathan@remexre.com>2024-01-16 00:57:41 -0600
committerNathan Ringo <nathan@remexre.com>2024-01-16 00:57:41 -0600
commited778ab2060c6131caf98231a97873d7ea490d5a (patch)
treebfa6ceca8fe2e209562c1e995c598d80be0e4501 /migrations
parent54f497163f57dacd8d621a2a3c89e1f06ac370d0 (diff)
The start of database functionality.
Diffstat (limited to 'migrations')
-rw-r--r--migrations/20240116060938_init_x500s.sql27
1 files changed, 27 insertions, 0 deletions
diff --git a/migrations/20240116060938_init_x500s.sql b/migrations/20240116060938_init_x500s.sql
new file mode 100644
index 0000000..3d5ca68
--- /dev/null
+++ b/migrations/20240116060938_init_x500s.sql
@@ -0,0 +1,27 @@
+-- We know all the X.500s of students we expect to have.
+CREATE TABLE IF NOT EXISTS student_x500s
+ ( x500 TEXT NOT NULL
+ , UNIQUE(x500)
+ );
+
+-- In the common case, we can just map users to their X.500s.
+CREATE TABLE IF NOT EXISTS uids_to_x500s_clean
+ ( uid TEXT NOT NULL
+ , x500 TEXT NOT NULL
+ , FOREIGN KEY(x500) REFERENCES student_x500s(x500)
+ , UNIQUE(uid)
+ , UNIQUE(x500)
+ );
+
+-- ...until we see someone change X.500, or try to take someone else's X.500,
+-- or use an unenrolled student's X.500.
+--
+-- These show up as a violation of one of the constraints in
+-- uids_to_x500s_clean. In that case, we still add the failing tuple to
+-- all_seen_uids_to_x500s. This lets us get a list of "suspicious tuples" by
+-- subtracting uids_to_x500s_clean from all_seen_uids_to_x500s.
+CREATE TABLE IF NOT EXISTS all_seen_uids_to_x500s
+ ( uid TEXT NOT NULL
+ , x500 TEXT NOT NULL
+ , UNIQUE(uid, x500)
+ );