| 1 | | -- table for school library |
| 2 | | CREATE TABLE resources ( |
| 3 | | id serial PRIMARY KEY, |
| 4 | | clasification varchar(40) NOT NULL UNIQUE, |
| 5 | | media smallint NOT NULL, -- Book, CD, LP, magazine |
| 6 | | title varchar (100), |
| 7 | | author varchar(90) NOT NULL, |
| 8 | | edition smallint, |
| 9 | | editor varchar(100), |
| 10 | | cost money, |
| 11 | | copies smallint NOT NULL DEFAULT 1 |
| | 1 | -- tables for school library |
| | 2 | |
| | 3 | CREATE TABLE types ( |
| | 4 | id serial PRIMARY KEY, |
| | 5 | type varchar(80) NOT NULL |
| | 8 | INSERT INTO types (type) VALUES ('Book'); |
| | 9 | INSERT INTO types (type) VALUES ('Magazine'); |
| | 10 | INSERT INTO types (type) VALUES ('Newspaper'); |
| | 11 | INSERT INTO types (type) VALUES ('DVD'); |
| | 12 | INSERT INTO types (type) VALUES ('CD'); |
| | 13 | |
| | 14 | |
| | 15 | CREATE TABLE resources ( |
| | 16 | id serial PRIMARY KEY, |
| | 17 | clasification varchar(40) NOT NULL UNIQUE, |
| | 18 | type_id smallint NOT NULL references types(id) ON DELETE CASCADE, -- Book, CD, LP, periodicals |
| | 19 | title varchar (100), |
| | 20 | author varchar(150) NOT NULL, |
| | 21 | edition smallint, |
| | 22 | editor varchar(100), |
| | 23 | isonumber varchar(20), --ISBN, ISSN, NS |
| | 24 | cost money DEFAULT '0.0', |
| | 25 | copies smallint NOT NULL DEFAULT 1, |
| | 26 | created timestamp(0) without time zone DEFAULT now() NOT NULL |
| | 27 | ); |
| | 28 | |
| | 29 | -- Prestamos |
| | 30 | CREATE TABLE lendings ( |
| | 31 | id serial PRIMARY KEY, |
| | 32 | resource_id int NOT NULL references resources(id), |
| | 33 | lend timestamp(0) without time zone DEFAULT now() NOT NULL, |
| | 34 | days smallint NOT NULL DEFAULT 7, |
| | 35 | user_id int NOT NULL references users(id) |
| | 36 | ); |