From e4901746617f82300ce0002b16fd3464b7233088 Mon Sep 17 00:00:00 2001 From: oysteini Date: Sat, 8 Oct 2011 09:00:42 +0000 Subject: [PATCH] =?UTF-8?q?SQL-fil=20for=20=C3=A5=20lage=20databasen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (Her formoder jeg at vi kvitter oss med Django og lager databasen selv isteden.) --- db/db.sql | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 db/db.sql diff --git a/db/db.sql b/db/db.sql new file mode 100644 index 0000000..b9baa97 --- /dev/null +++ b/db/db.sql @@ -0,0 +1,68 @@ +CREATE TABLE kategori +(id text PRIMARY KEY, + navn text NOT NULL); + +CREATE TABLE plassering +(id SERIAL PRIMARY KEY, + kategori text NOT NULL REFERENCES kategori (id), + hylle text NOT NULL); + +CREATE TABLE bokserie +(id text PRIMARY KEY, + tittel text NOT NULL); + +CREATE TABLE bok +(isbn text PRIMARY KEY, + id text NOT NULL, + tittel text NOT NULL, + undertittel text, + kategori text NOT NULL REFERENCES kategori (id), + forlag text, + utgivelsesaar integer, + utgave text, + sidetall integer, + serie text REFERENCES bokserie (id), + beskrivelse text); -- TODO: bilde? + +CREATE TABLE alternativ_tittel +(id SERIAL PRIMARY KEY, + bok text NOT NULL REFERENCES bok (isbn), + alt_tittel text NOT NULL); + +CREATE TABLE eksemplar +(bok text REFERENCES bok (isbn), + nummer integer, + eier text, + PRIMARY KEY(bok, nummer)); + +CREATE TABLE person +(id text PRIMARY KEY, + etternavn text NOT NULL, + fornavn text NOT NULL); + +CREATE TABLE rolle +(id text PRIMARY KEY, + navn text NOT NULL); + +CREATE TABLE bokperson +(id SERIAL PRIMARY KEY, + bok text NOT NULL REFERENCES bok (isbn), + person text NOT NULL REFERENCES person (id), + relasjon text NOT NULL REFERENCES rolle (id)); + +CREATE TABLE referansetype +(id text PRIMARY KEY, + navn text NOT NULL); + +CREATE TABLE bokreferanse +(id SERIAL PRIMARY KEY, + bok text NOT NULL REFERENCES bok (isbn), + reftype text NOT NULL REFERENCES referansetype (id), + tekst text NOT NULL); + +CREATE TABLE personreferanse +(id SERIAL PRIMARY KEY, + person text NOT NULL REFERENCES person (id), + reftype text NOT NULL REFERENCES referansetype (id), + tekst text NOT NULL); +