Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 259 lines (220 sloc) 9.579 kb
3e96cf5 Moritz Lenz [model] move DROP TABLEs to the top
authored
1 -- all DROP TABLEs need to go first, so that newly created tables
2 -- don't add dependencies to to-be-deleted tables
3 DROP TABLE IF EXISTS title CASCADE;
4a2905e Moritz Lenz [model] add title_link table
authored
4 DROP TABLE IF EXISTS title_link;
3e96cf5 Moritz Lenz [model] move DROP TABLEs to the top
authored
5 DROP TABLE IF EXISTS publication CASCADE;
6 DROP TABLE IF EXISTS raw_publication CASCADE;
7 DROP TABLE IF EXISTS raw_publication_attribution;
8 DROP TABLE IF EXISTS user_login CASCADE;
9 DROP TABLE IF EXISTS user_info;
10 DROP TABLE IF EXISTS title_attribution;
11 DROP TABLE IF EXISTS publication_attribution;
12 DROP TABLE IF EXISTS author CASCADE;
13 DROP TABLE IF EXISTS author_title_map;
eb7686e Moritz Lenz [model] drop and create stuff in the right order; drop view
authored
14 DROP VIEW IF EXISTS author_wiki_link_count;
3e96cf5 Moritz Lenz [model] move DROP TABLEs to the top
authored
15 DROP TABLE IF EXISTS author_link;
16 DROP TABLE IF EXISTS author_attribution;
17 DROP TABLE IF EXISTS publisher CASCADE;
18 DROP TABLE IF EXISTS publisher_link;
19
ef08587 Moritz Lenz [model] created/modified columns for some tables
authored
20 -- trigger function from
21 -- http://www.revsys.com/blog/2006/aug/04/automatically-updating-a-timestamp-column-in-postgresql/
22 CREATE OR REPLACE FUNCTION update_modified_column()
23 RETURNS TRIGGER AS $$
24 BEGIN
25 NEW.modified = now();
26 RETURN NEW;
27 END;
28 $$ language 'plpgsql';
29
3e96cf5 Moritz Lenz [model] move DROP TABLEs to the top
authored
30 DROP TYPE bookbinding;
7e32524 Moritz Lenz [model] recording binding and number of pages
authored
31 CREATE TYPE bookbinding AS ENUM('paperback', 'hardcover', 'pamphlet', 'digest',
32 'ebook', 'audio', 'video');
ef08587 Moritz Lenz [model] created/modified columns for some tables
authored
33
2d9ade5 Moritz Lenz start to separate title and publication. Compiles, but does not run yet.
authored
34 CREATE TABLE title (
b67747c Moritz Lenz introduce MediaLink.pm
authored
35 id SERIAL primary key,
7e32524 Moritz Lenz [model] recording binding and number of pages
authored
36 title VARCHAR(512) NOT NULL,
d7a79f9 Moritz Lenz [model] s/language/lang/g
authored
37 lang CHAR(2),
2d9ade5 Moritz Lenz start to separate title and publication. Compiles, but does not run yet.
authored
38
e6e03d5 Moritz Lenz [model] remove author and publisher from Title; add isfdb_id
authored
39 isfdb_id INTEGER UNIQUE,
2d9ade5 Moritz Lenz start to separate title and publication. Compiles, but does not run yet.
authored
40 -- NestedSet columns:
41 root_id INTEGER REFERENCES title (id) ON DELETE CASCADE,
2004d1c Moritz Lenz [model] add language field
authored
42 l INTEGER NOT NULL DEFAULT(1),
43 r INTEGER NOT NULL DEFAULT(2),
ef08587 Moritz Lenz [model] created/modified columns for some tables
authored
44 level INTEGER NOT NULL DEFAULT(1),
507bc92 Moritz Lenz [model] comment schema.sql a bit, and shuffle the order of a few columns...
authored
45
46 -- used to mark translations
47 -- translations should have set same_as to the title.id of the
48 -- title in the original language
49 same_as INTEGER REFERENCES title (id) ON DELETE CASCADE,
50
ef08587 Moritz Lenz [model] created/modified columns for some tables
authored
51 created TIMESTAMP NOT NULL DEFAULT NOW(),
11ab976 Moritz Lenz [model] allow just one translations per title and language
authored
52 modified TIMESTAMP NOT NULL DEFAULT NOW(),
53 UNIQUE(same_as, lang)
bab9a73 Moritz Lenz display and confirm raw publications; be less strict in the schema, othe...
authored
54 -- CHECK(r > l)
55 -- CHECK((r - l) % 2 = 1)
b67747c Moritz Lenz introduce MediaLink.pm
authored
56 );
ef08587 Moritz Lenz [model] created/modified columns for some tables
authored
57 CREATE TRIGGER update_title_modtime BEFORE UPDATE ON title FOR EACH ROW EXECUTE PROCEDURE update_modified_column();
f6f37cb Moritz Lenz more datasets, and some printing; currently broken
authored
58
2d9ade5 Moritz Lenz start to separate title and publication. Compiles, but does not run yet.
authored
59 CREATE INDEX title_root_id_idx on title (root_id);
60
4a2905e Moritz Lenz [model] add title_link table
authored
61 CREATE TABLE title_link (
62 id SERIAL PRIMARY KEY,
63 title_id INTEGER NOT NULL REFERENCES title (id) ON DELETE CASCADE,
64 url VARCHAR(512) NOT NULL,
baaf552 Moritz Lenz [model] rename column for consistency sake
authored
65 type VARCHAR(255) NOT NULL,
3f6dddf Moritz Lenz [model] be stricter with title_links
authored
66 lang CHAR(2),
67 -- an URL can be entered for two languages, since
68 -- content negotion exists.
69 UNIQUE(title_id, url, lang)
4a2905e Moritz Lenz [model] add title_link table
authored
70 );
71
72 CREATE INDEX title_link_title_id_idx on title_link (title_id);
73
eb7686e Moritz Lenz [model] drop and create stuff in the right order; drop view
authored
74 CREATE TABLE publisher (
75 id SERIAL PRIMARY KEY,
76 isfdb_id INTEGER UNIQUE,
77 name VARCHAR(255) NOT NULL UNIQUE
78 );
79
80 CREATE TABLE publisher_link (
81 id SERIAL PRIMARY KEY,
82 publisher_id INTEGER NOT NULL REFERENCES publisher (id) ON DELETE CASCADE,
83 type VARCHAR(64) NOT NULL,
84 url VARCHAR(255) NOT NULL
85 );
86 CREATE INDEX publisher_link_publisher_id_idx ON publisher_link (publisher_id);
87
2d9ade5 Moritz Lenz start to separate title and publication. Compiles, but does not run yet.
authored
88 CREATE TABLE publication (
89 id SERIAL primary key,
90 asin CHAR(10) UNIQUE,
2851a32 Moritz Lenz rename ISBN to isbn
authored
91 isbn VARCHAR(13),
ea77a2e Moritz Lenz add libris_id to the schema
authored
92 libris_id VARCHAR(24) UNIQUE,
7e32524 Moritz Lenz [model] recording binding and number of pages
authored
93 title VARCHAR(512) NOT NULL,
d80cbce Moritz Lenz more over-engineering: publishers
authored
94 publisher_id INTEGER REFERENCES publisher (id),
0d6e54d Moritz Lenz [model] start fixing up result sets
authored
95 lang CHAR(2),
7e32524 Moritz Lenz [model] recording binding and number of pages
authored
96 -- cannot make NOT NULL because of how import from isfdb
97 -- works. TODO: fixup later
4895cc3 Moritz Lenz [model] add a missing ON DELETE CASCADE
authored
98 title_id INTEGER REFERENCES title (id) ON DELETE CASCADE,
0d6e54d Moritz Lenz [model] start fixing up result sets
authored
99
2d9ade5 Moritz Lenz start to separate title and publication. Compiles, but does not run yet.
authored
100 amazon_url VARCHAR(255),
101 publication_date DATE,
7e32524 Moritz Lenz [model] recording binding and number of pages
authored
102 binding bookbinding,
103 pages INTEGER,
2d9ade5 Moritz Lenz start to separate title and publication. Compiles, but does not run yet.
authored
104
105 small_image VARCHAR(255),
106 small_image_width INTEGER,
107 small_image_height INTEGER,
108
109 medium_image VARCHAR(255),
110 medium_image_width INTEGER,
111 medium_image_height INTEGER,
112
113 large_image VARCHAR(255),
114 large_image_width INTEGER,
ef08587 Moritz Lenz [model] created/modified columns for some tables
authored
115 large_image_height INTEGER,
116
117 created TIMESTAMP NOT NULL DEFAULT NOW(),
118 modified TIMESTAMP NOT NULL DEFAULT NOW()
2d9ade5 Moritz Lenz start to separate title and publication. Compiles, but does not run yet.
authored
119 );
26c7124 Moritz Lenz first shot at login backend (untested)
authored
120
ef08587 Moritz Lenz [model] created/modified columns for some tables
authored
121 CREATE TRIGGER update_publication_modtime BEFORE UPDATE ON publication FOR EACH ROW EXECUTE PROCEDURE update_modified_column();
122
be23224 Moritz Lenz add some more indexes
authored
123 CREATE INDEX publication_title_id_idx on publication (title_id);
124 CREATE INDEX publication_publisher_id_idx on publication (publisher_id);
125
40d7990 Moritz Lenz add RawPublication, which is roughly what the very first version of Titl...
authored
126
127 CREATE TABLE raw_publication (
128 id SERIAL primary key,
129 asin CHAR(10) UNIQUE,
ea77a2e Moritz Lenz add libris_id to the schema
authored
130 libris_id VARCHAR(24) UNIQUE,
40d7990 Moritz Lenz add RawPublication, which is roughly what the very first version of Titl...
authored
131 isbn VARCHAR(13) UNIQUE,
7e32524 Moritz Lenz [model] recording binding and number of pages
authored
132 title VARCHAR(512) NOT NULL,
40d7990 Moritz Lenz add RawPublication, which is roughly what the very first version of Titl...
authored
133 authors VARCHAR(512),
134 publisher VARCHAR(255),
135 lang CHAR(2),
136
bab9a73 Moritz Lenz display and confirm raw publications; be less strict in the schema, othe...
authored
137 maybe_title_id INTEGER REFERENCES title (id) ON DELETE CASCADE,
7e32524 Moritz Lenz [model] recording binding and number of pages
authored
138
40d7990 Moritz Lenz add RawPublication, which is roughly what the very first version of Titl...
authored
139 amazon_url VARCHAR(255),
140 publication_date DATE,
7e32524 Moritz Lenz [model] recording binding and number of pages
authored
141 binding bookbinding,
142 pages INTEGER,
40d7990 Moritz Lenz add RawPublication, which is roughly what the very first version of Titl...
authored
143
144 small_image VARCHAR(255),
145 small_image_width INTEGER,
146 small_image_height INTEGER,
147
148 medium_image VARCHAR(255),
149 medium_image_width INTEGER,
150 medium_image_height INTEGER,
151
152 large_image VARCHAR(255),
153 large_image_width INTEGER,
154 large_image_height INTEGER,
155
156 created TIMESTAMP NOT NULL DEFAULT NOW(),
157 modified TIMESTAMP NOT NULL DEFAULT NOW()
158 );
159 CREATE TRIGGER update_raw_publication_modtime BEFORE UPDATE ON raw_publication FOR EACH ROW EXECUTE PROCEDURE update_modified_column();
160
161 CREATE TABLE raw_publication_attribution (
162 id SERIAL PRIMARY KEY,
163 raw_publication_id INTEGER NOT NULL REFERENCES raw_publication (id) ON DELETE CASCADE,
164 name VARCHAR(64) NOT NULL,
165 url VARCHAR(255),
166 retrieved DATE DEFAULT CURRENT_DATE
167 );
168 CREATE INDEX raw_publication_attribution_raw_publication_id on raw_publication_attribution (raw_publication_id);
169
f81c774 Moritz Lenz make login logic work
authored
170 CREATE TABLE user_login (
26c7124 Moritz Lenz first shot at login backend (untested)
authored
171 id SERIAL PRIMARY KEY,
172 name VARCHAR(64) UNIQUE,
173 salt BYTEA NOT NULL,
174 cost INTEGER NOT NULL,
ef08587 Moritz Lenz [model] created/modified columns for some tables
authored
175 pw_hash BYTEA NOT NULL,
176 created TIMESTAMP NOT NULL DEFAULT NOW(),
177 modified TIMESTAMP NOT NULL DEFAULT NOW()
26c7124 Moritz Lenz first shot at login backend (untested)
authored
178 );
ef08587 Moritz Lenz [model] created/modified columns for some tables
authored
179 CREATE TRIGGER update_user_login_modtime BEFORE UPDATE ON user_login FOR EACH ROW EXECUTE PROCEDURE update_modified_column();
574ee7a Moritz Lenz [model] (sparse) user info
authored
180
181 CREATE TABLE user_info (
2d9ade5 Moritz Lenz start to separate title and publication. Compiles, but does not run yet.
authored
182 id SERIAL PRIMARY KEY,
5bcde5c Moritz Lenz [model] on delete cascade
authored
183 login_id INTEGER NOT NULL REFERENCES user_login (id) ON DELETE CASCADE,
2d9ade5 Moritz Lenz start to separate title and publication. Compiles, but does not run yet.
authored
184 real_name VARCHAR(64),
185 email VARCHAR(255)
186 );
be23224 Moritz Lenz add some more indexes
authored
187 CREATE INDEX user_info_login_id_idx on user_info (login_id);
2d9ade5 Moritz Lenz start to separate title and publication. Compiles, but does not run yet.
authored
188
189 CREATE TABLE title_attribution (
190 id SERIAL PRIMARY KEY,
5bcde5c Moritz Lenz [model] on delete cascade
authored
191 title_id INTEGER NOT NULL REFERENCES title (id) ON DELETE CASCADE,
2d9ade5 Moritz Lenz start to separate title and publication. Compiles, but does not run yet.
authored
192 name VARCHAR(64) NOT NULL,
193 url VARCHAR(255),
194 retrieved DATE DEFAULT CURRENT_DATE
574ee7a Moritz Lenz [model] (sparse) user info
authored
195 );
be23224 Moritz Lenz add some more indexes
authored
196 CREATE INDEX title_attributioin_title_id on title_attribution (title_id);
de54b5d Moritz Lenz [model] implement and test attributions; automatically create amazon att...
authored
197
2d9ade5 Moritz Lenz start to separate title and publication. Compiles, but does not run yet.
authored
198 CREATE TABLE publication_attribution (
199 id SERIAL PRIMARY KEY,
5bcde5c Moritz Lenz [model] on delete cascade
authored
200 publication_id INTEGER NOT NULL REFERENCES publication (id) ON DELETE CASCADE,
2d9ade5 Moritz Lenz start to separate title and publication. Compiles, but does not run yet.
authored
201 name VARCHAR(64) NOT NULL,
202 url VARCHAR(255),
203 retrieved DATE DEFAULT CURRENT_DATE
de54b5d Moritz Lenz [model] implement and test attributions; automatically create amazon att...
authored
204 );
be23224 Moritz Lenz add some more indexes
authored
205 CREATE INDEX publication_attribution_publication_id on publication_attribution (publication_id);
dd538d4 Moritz Lenz [model] start to store authors separately
authored
206
207 CREATE TABLE author (
208 id SERIAL PRIMARY KEY,
7a797a1 Moritz Lenz author listings
authored
209 -- for import from isfdb.org
210 isfdb_id INTEGER UNIQUE,
6099259 Moritz Lenz also add libris_id for author
authored
211 libris_id VARCHAR(24) UNIQUE,
418611e Moritz Lenz author attributions
authored
212 -- TODO: figure out if that should really be UNIQUE
213 name VARCHAR(255) NOT NULL UNIQUE,
dd538d4 Moritz Lenz [model] start to store authors separately
authored
214 legal_name VARCHAR(255),
215 birthplace VARCHAR(64),
216 birthplace_lat FLOAT,
217 birthplace_lon FLOAT,
218 birthdate DATE,
ef08587 Moritz Lenz [model] created/modified columns for some tables
authored
219 deathdate DATE,
220 created TIMESTAMP NOT NULL DEFAULT NOW(),
221 modified TIMESTAMP NOT NULL DEFAULT NOW()
dd538d4 Moritz Lenz [model] start to store authors separately
authored
222 );
ef08587 Moritz Lenz [model] created/modified columns for some tables
authored
223 CREATE TRIGGER update_author_modtime BEFORE UPDATE ON author FOR EACH ROW EXECUTE PROCEDURE update_modified_column();
dd538d4 Moritz Lenz [model] start to store authors separately
authored
224
225 CREATE TABLE author_title_map (
226 id SERIAL PRIMARY KEY,
5bcde5c Moritz Lenz [model] on delete cascade
authored
227 author_id INTEGER NOT NULL REFERENCES author (id) ON DELETE CASCADE,
228 title_id INTEGER NOT NULL REFERENCES title (id) ON DELETE CASCADE,
dd538d4 Moritz Lenz [model] start to store authors separately
authored
229 UNIQUE(author_id, title_id)
230 );
231
232 CREATE TABLE author_link (
233 id SERIAL PRIMARY KEY,
5bcde5c Moritz Lenz [model] on delete cascade
authored
234 author_id INTEGER NOT NULL REFERENCES author (id) ON DELETE CASCADE,
dd538d4 Moritz Lenz [model] start to store authors separately
authored
235 type VARCHAR(64) NOT NULL,
433f1b1 Moritz Lenz [model] some non-ASCII wiki URLs are quite long...
authored
236 url VARCHAR(512) NOT NULL,
08c5fcf Moritz Lenz [model] tweak author links
authored
237 lang CHAR(2),
238 UNIQUE(author_id, url)
dd538d4 Moritz Lenz [model] start to store authors separately
authored
239 );
be23224 Moritz Lenz add some more indexes
authored
240 CREATE INDEX author_link_author_id_idx ON author_link (author_id);
418611e Moritz Lenz author attributions
authored
241
dbc5b68 Moritz Lenz [model] prepare a useless gimmick: authors by number of wikipedia transl...
authored
242 -- just a gimmick for useless statistics
243 CREATE OR REPLACE VIEW author_wiki_link_count ( author_id, link_count )
244 AS SELECT author_id, count(author_id)
245 FROM author_link
246 WHERE type = 'wikipedia'
247 GROUP BY author_id
248 ;
249
418611e Moritz Lenz author attributions
authored
250 CREATE TABLE author_attribution (
251 id SERIAL PRIMARY KEY,
5bcde5c Moritz Lenz [model] on delete cascade
authored
252 author_id INTEGER NOT NULL REFERENCES author (id) ON DELETE CASCADE,
418611e Moritz Lenz author attributions
authored
253 name VARCHAR(64) NOT NULL,
254 url VARCHAR(255),
255 retrieved DATE DEFAULT CURRENT_DATE
256 );
be23224 Moritz Lenz add some more indexes
authored
257 CREATE INDEX author_attribution_author_id on author_attribution (author_id);
d80cbce Moritz Lenz more over-engineering: publishers
authored
258
Something went wrong with that request. Please try again.