Commit bdd55772 authored by Stephane Crozat's avatar Stephane Crozat

add install & sql

parent d6900121
DROP USER apisub;
CREATE USER apisub WITH ENCRYPTED PASSWORD 'password';
DROP DATABASE apisub;
CREATE DATABASE apisub;
GRANT ALL PRIVILEGES ON DATABASE apisub TO apisub;
/** CTRL+ALT+P to view **/
@startuml
hide circle
class Student {
utclogin : text {key}
mail : mail {key}
surname : text
firstname : text
}
class Api {
code : integer {key}
name : text
year : year
semester : H|E
}
note right of Api : (name,year,semester) key
Student "0..n" - "0..n" Api
(Student, Api) . Subscribe
class Subscribe {
subdate : date
}
@enduml
DROP TABLE IF EXISTS subscribe CASCADE;
DROP TABLE IF EXISTS api;
CREATE TABLE api (
code INTEGER PRIMARY KEY,
name TEXT NOT NULL,
year INTEGER NOT NULL,
semester CHAR(1) NOT NULL,
CHECK (code>0),
CHECK (year>2018 AND year<2100),
CHECK (semester IN ('H','E')),
UNIQUE (name,year,semester)
);
CREATE TABLE subscribe (
utclogin TEXT NOT NULL,
api INTEGER REFERENCES api(code),
subdate DATE NOT NULL,
PRIMARY KEY (utclogin,api)
);
/** Test dataset **/
INSERT INTO api VALUES (
1,'Poésie et ingénierie',2019,'H'
);
INSERT INTO api VALUES (
2,'Cloud big data blockchain IA',2019,'H'
);
INSERT INTO subscribe VALUES (
'crozatst',1,TO_DATE('20181018','YYYYMMDD')
);
CREATE VIEW vSubscrition AS
SELECT ap.code, ap.name, ap.year, ap.semester, su.subdate, su.utclogin FROM
subscribe su JOIN api ap ON ap.code=su.api
ORDER BY ap.year, ap.semester, su.utclogin, ap.code;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment