-
Notifications
You must be signed in to change notification settings - Fork 0
/
librarian.sql
132 lines (121 loc) · 4.21 KB
/
librarian.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
CREATE TABLE IF NOT EXISTS librarians(
librarianid INTEGER AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
canread BOOLEAN NOT NULL,
canwrite BOOLEAN NOT NULL,
canexec BOOLEAN NOT NULL,
lastupdate TIMESTAMP NOT NULL,
lastupdateby INTEGER NOT NULL
) ENGINE = INNODB;
CREATE TABLE IF NOT EXISTS books(
isbn VARCHAR(13) PRIMARY KEY,
title VARCHAR(255) NOT NULL,
year INTEGER NOT NULL,
lastupdate TIMESTAMP NOT NULL,
lastupdateby INTEGER NOT NULL,
FOREIGN KEY (lastupdateby) REFERENCES librarians (librarianid)
) ENGINE = INNODB;
CREATE TABLE IF NOT EXISTS bookcompanies(
companyid INTEGER PRIMARY KEY AUTO_INCREMENT,
companyname VARCHAR(255) UNIQUE NOT NULL,
lastupdate TIMESTAMP NOT NULL,
lastupdateby INTEGER NOT NULL,
FOREIGN KEY (lastupdateby) REFERENCES librarians (librarianid)
) ENGINE = INNODB;
CREATE TABLE IF NOT EXISTS imprints(
mothercompany INTEGER,
imprintcompany INTEGER,
lastupdate TIMESTAMP NOT NULL,
lastupdateby INTEGER NOT NULL,
FOREIGN KEY (lastupdateby) REFERENCES librarians (librarianid),
FOREIGN KEY (mothercompany) REFERENCES bookcompanies (companyid),
FOREIGN KEY (imprintcompany) REFERENCES bookcompanies (companyid),
PRIMARY KEY (mothercompany, imprintcompany)
) ENGINE = INNODB;
CREATE TABLE IF NOT EXISTS leafmakers(
isbn VARCHAR(13),
companyid INTEGER,
ispublisher BOOLEAN NOT NULL DEFAULT FALSE,
isprinter BOOLEAN NOT NULL DEFAULT FALSE,
lastupdate TIMESTAMP NOT NULL,
lastupdateby INTEGER NOT NULL,
FOREIGN KEY (lastupdateby) REFERENCES librarians (librarianid),
FOREIGN KEY (isbn) REFERENCES books (isbn),
FOREIGN KEY (companyid) REFERENCES bookcompanies (companyid),
PRIMARY KEY (isbn, companyid)
) ENGINE = INNODB;
CREATE TABLE IF NOT EXISTS bookpersons(
personid INTEGER PRIMARY KEY AUTO_INCREMENT,
lastname VARCHAR(255) NOT NULL,
firstname VARCHAR(255) NOT NULL,
lastupdate TIMESTAMP NOT NULL,
lastupdateby INTEGER NOT NULL,
FOREIGN KEY (lastupdateby) REFERENCES librarians (librarianid),
CONSTRAINT uniqueNames UNIQUE (lastname, firstname)
) ENGINE = INNODB;
CREATE TABLE IF NOT EXISTS roles(
roleid INTEGER PRIMARY KEY AUTO_INCREMENT,
rolename VARCHAR(255) UNIQUE NOT NULL,
roledisplay VARCHAR(255) NOT NULL,
lastupdate TIMESTAMP NOT NULL,
lastupdateby INTEGER NOT NULL,
FOREIGN KEY (lastupdateby) REFERENCES librarians (librarianid)
) ENGINE = INNODB;
CREATE TABLE IF NOT EXISTS bookparticipants(
isbn VARCHAR(13),
personid INTEGER,
roleid INTEGER,
lastupdate TIMESTAMP NOT NULL,
lastupdateby INTEGER NOT NULL,
FOREIGN KEY (lastupdateby) REFERENCES librarians (librarianid),
FOREIGN KEY (isbn) REFERENCES books (isbn),
FOREIGN KEY (personid) REFERENCES bookpersons (personid),
FOREIGN KEY (roleid) REFERENCES roles (roleid),
PRIMARY KEY (isbn, personid, roleid)
) ENGINE = INNODB;
/**
Is this table ever going into any use?
*/
CREATE TABLE IF NOT EXISTS pseudonyms(
personid INTEGER,
isbn VARCHAR(13),
pseudolast VARCHAR(255) NOT NULL,
pseudofirst VARCHAR(255) NOT NULL,
lastupdate TIMESTAMP NOT NULL,
lastupdateby INTEGER NOT NULL,
FOREIGN KEY (lastupdateby) REFERENCES librarians (librarianid),
FOREIGN KEY (personid) REFERENCES bookpersons (personid),
FOREIGN KEY (isbn) REFERENCES books (isbn),
PRIMARY KEY (personid, isbn)
) ENGINE = INNODB;
CREATE TABLE IF NOT EXISTS genres(
genreid INTEGER PRIMARY KEY AUTO_INCREMENT,
genrename VARCHAR(20),
lastupdate TIMESTAMP NOT NULL,
lastupdateby INTEGER NOT NULL,
FOREIGN KEY (lastupdateby) REFERENCES librarians (librarianid)
) ENGINE = INNODB;
CREATE TABLE IF NOT EXISTS bookgenres(
genreid INTEGER,
isbn VARCHAR(13),
lastupdate TIMESTAMP NOT NULL,
lastupdateby INTEGER NOT NULL,
FOREIGN KEY (lastupdateby) REFERENCES librarians (librarianid),
FOREIGN KEY (genreid) REFERENCES genres (genreid),
FOREIGN KEY (isbn) REFERENCES books (isbn),
PRIMARY KEY (genreid, isbn)
) ENGINE = INNODB;
/**
This will act like a hash map of setting values.
*/
CREATE TABLE IF NOT EXISTS appsettings(
settingcode VARCHAR(50) PRIMARY KEY,
classes VARCHAR(255),
settingstring VARCHAR(100) NOT NULL,
description VARCHAR(255),
settingvalue VARCHAR(255),
lastupdate TIMESTAMP NOT NULL,
lastupdateby INTEGER NOT NULL,
FOREIGN KEY (lastupdateby) REFERENCES librarians (librarianid)
) ENGINE = INNODB;