This commit is contained in:
2025-09-30 07:40:56 +02:00
parent 1d35e1b184
commit 39c73db7e8
3 changed files with 16425 additions and 93 deletions

View File

@@ -13,6 +13,7 @@ drop table if exists editions;
drop table if exists exemplaires;
drop table if exists genres;
drop table if exists collections;
drop table if exists incorpore;
drop table if exists adherents;
drop table if exists adresses;
@@ -24,155 +25,233 @@ drop table if exists commande;
drop table if exists commande_statut;
drop table if exists livraison_methode;
--
PRAGMA integrity_check;
PRAGMA foreign_key_check;
-- ************************************************************
pragma integrity_check;
pragma foreign_key_check;
-- ************************************************************
CREATE TABLE statuts (
statutId INTEGER PRIMARY KEY,
statut TEXT NOT NULL
);
CREATE TABLE pays (
code TEXT PRIMARY KEY CHECK (LENGTH(code) = 2),
nom TEXT NOT NULL
);
insert into pays values
('FR', 'France'), ('GB', 'Royaume-Uni'), ('US', 'États-Unis'), ('TR', 'Türkiye');
CREATE TABLE langues (
langue_id INTEGER,
langue_code VARCHAR(5) PRIMARY KEY,
langue TEXT
code TEXT PRIMARY KEY CHECK (LENGTH(code) = 2 or LENGTH(code) = 5),
nom TEXT NOT NULL
);
insert into langues values
('fr', 'français'), ('tr', 'turc'),
('en', 'anglais'), ('en-gb', 'anglais britannique'), ('en-us', 'anglais américain');
CREATE TABLE genres (
genreId INTEGER PRIMARY KEY,
nom TEXT NOT NULL
);
insert into genres (nom) values
('space opera'), ('horreur'), ('fiction historique');
CREATE TABLE auteurs (
auteur_id INTEGER PRIMARY KEY,
Nom TEXT DEFAULT NULL
auteurId INTEGER PRIMARY KEY,
nom TEXT NOT NULL,
[references] TEXT DEFAULT NULL
);
insert into auteurs values
(3076,'Graham Masterton','https://www.noosfere.org/livres/auteur.asp?numauteur=19'),
(8222,'Stephen King','https://www.noosfere.org/livres/auteur.asp?NumAuteur=97'),
(9256,'Pierre Bordage','https://www.noosfere.org/livres/auteur.asp?NumAuteur=28'),
(9912,'Elif Şafak', 'https://www.babelio.com/auteur/Elif-Shafak/22574');
CREATE TABLE editeurs (
editeur_id INTEGER PRIMARY KEY,
Nom TEXT
editeurId INTEGER PRIMARY KEY,
nom TEXT NOT NULL
);
insert into editeurs (nom) values
('L''Atalante'), ('J''Ai Lu'), ('10/18'), ('Viking'), ('Penguin Books'), ('Le Livre de Poche');
CREATE TABLE collections (
collectionId INTEGER PRIMARY KEY,
nom TEXT NOT NULL
);
insert into collections (nom) values
('Bibliothèque de l''évasion'), ('Science-Fiction');
CREATE TABLE series (
serie_id INTEGER PRIMARY KEY,
Nom TEXT
serieId INTEGER PRIMARY KEY,
nom TEXT NOT NULL
);
insert into series values
(1, 'Les Guerriers du silence');
-- ************************************************************
CREATE TABLE oeuvres (
oeuvre_id INTEGER PRIMARY KEY,
oeuvreId INTEGER PRIMARY KEY,
titre TEXT,
isbn13 TEXT,
langue_code VARCHAR(5) REFERENCES langues (langue_code),
num_pages INTEGER,
publication_date DATE,
editeur_id INTEGER,
genre_id INTEGER,
serie_id INTEGER,
CONSTRAINT fk_oeuvre_editeur FOREIGN KEY (editeur_id) REFERENCES editeurs (editeur_id),
CONSTRAINT fk_oeuvre_genre FOREIGN KEY (genre_id) REFERENCES genres (genre_id),
CONSTRAINT fk_oeuvre_serie FOREIGN KEY (serie_id) REFERENCES series (serie_id)
langueCode TEXT REFERENCES langues (langue_code),
publicationDate DATE,
genreId integer references genres (genreId),
serie_id integer references series (serie_id)
);
insert into oeuvres values
(1, 'Les Guerriers du silence','fr', 1993, 1, 1),
(2, 'Terra Mater', 'fr', 1994, 1, 1),
(3, 'La Citadelle Hyponéros', 'fr', 1995, 1, 1),
(4, 'The Forty Rules of Love', 'en', 2009, 3, NULL),
(5, 'Salem''s Lot', 'en', 1975, 2, NULL),
(6, 'The Shining', 'en', 1977, 2, NULL),
(7, 'The Stand', 'en', 1978, 2, NULL),
(8, 'The Long Walk', 'en', 1975, 2, NULL),
(9, 'Charlie', 'en', 1980, 2, NULL),
(10, 'IT', 'en', 1986, 2, NULL),
(11, 'The Stand: The Complete & Uncut Edition', 'en', 1990, 2, NULL),
(12, 'The Tommyknockers', 'en', 1987,2,NULL),
(13, 'Pet Sematary', 'en', 1983, 2,NULL),
(14, 'Chritine', 'en', 1983, 2,NULL),
(15, 'Firestarter', 'en', 1980, 2,NULL);
create table participe (
oeuvre_id INTEGER NOT NULL REFERENCES oeuvres (oeuvre_id),
auteur_id INTEGER NOT NULL REFERENCES auteurs (auteur_id),
fonction TEXT,
alias TEXT,
CONSTRAINT pk_oeuvreauteur PRIMARY KEY (oeuvre_id, auteur_id)
);
insert into participe values
(1, 8222, 'auteur', NULL), (2, 8222, 'auteur', NULL), (3, 8222, 'auteur', NULL),
(4, 9912, 'auteur', NULL),
(5, 8222, 'auteur', NULL),(6, 8222, 'auteur', NULL),(7, 8222, 'auteur', NULL),
(8, 8222, 'auteur', 'Richard Bachman'),(9, 8222, 'auteur', NULL),(10, 8222, 'auteur', NULL),
(11, 8222, 'auteur', NULL),(12, 8222, 'auteur', NULL),(13, 8222, 'auteur', NULL),
(14, 8222, 'auteur', NULL), (15, 8222, 'auteur', NULL);
CREATE TABLE editions (
edition_id INTEGER PRIMARY KEY,
oeuvre_id INTEGER REFERENCES oeuvres (oeuvre_id),
editeur_id INTEGER REFERENCES editeurs (editeur_id),
editionId INTEGER PRIMARY KEY,
editeurId INTEGER REFERENCES editeurs (editeurId),
isbn13 TEXT,
langue_code VARCHAR(5) REFERENCES langues (langue_code),
langueCode TEXT REFERENCES langues (langueCode),
publication_date DATE,
num_pages INTEGER,
num_catalogue INTEGER
titre TEXT,
informations TEXT
);
insert into editions values
(1, 1, '978-2-9051-5869-7', 'fr', '1993-04-01', 704, 'Les Guerriers du silence', NULL),
(2, 1, '978-2-2903-1901-7', 'fr', '1994-05-01', 672, 'Terra Mater', NULL),
(3, 1, '978-2-2903-3137-8', 'fr', '1995-06-01', 720, 'La Citadelle Hyponéros', NULL),
(4, 4, '978-0-1410-4718-8', 'en', '2010-02-18', 354, 'The Forty Rules of Love', NULL),
(5, 3, '978-2-2640-5406-7', 'fr', '2011-08-18', 480, 'Soufi, mon amour', '{ "traducteur": "Dominique Letellier" }'),
(6, 2, '978-2-277-22326-3', 'fr', '1988-01-01', 576, 'Le Fléau', '{ "traducteur": "Richard Matas", "couverture": "Matthieu Blanchin", "catégorie": "6", "collection": "Épouvante", "num catalogue": 2326 }'),
(7, 2, '978-2-277-23311-0', 'fr', '1992-09-01', 512, 'Le Fléau - 1', '{ "traducteur": "Jean-Pierre Quijano", "couverture": "Matthieu Blanchin", "catégorie": "6", "collection": "Épouvante", "num catalogue": 3311 }'),
(8, 2, '978-2-277-23312-9', 'fr', '1992-09-01', 512, 'Le Fléau - 2', '{ "traducteur": "Jean-Pierre Quijano", "couverture": "Matthieu Blanchin", "catégorie": "6", "collection": "Épouvante", "num catalogue": 3312 }'),
(9, 2, '978-2-277-23313-7', 'fr', '1992-09-01', 512, 'Le Fléau - 3', '{ "traducteur": "Jean-Pierre Quijano", "couverture": "Matthieu Blanchin", "catégorie": "6", "collection": "Épouvante", "num catalogue": 3313 }'),
(10, 6, '978-2-253-15141-8', 'fr', '2003-08-01', 768, 'Le Fléau - 1', '{ "traducteur": "Jean-Pierre Quijano", "couverture": "Philippe Brault", "num catalogue": 15141 }'),
(11, 6, '978-2-253-15142-4', 'fr', '2003-08-01', 800, 'Le Fléau - 2', '{ "traducteur": "Jean-Pierre Quijano", "couverture": "Philippe Brault", "num catalogue": 15142 }')
;
CREATE TABLE incorpore (
oeuvreId INTEGER NOT NULL REFERENCES oeuvres (oeuvreId),
editionId INTEGER NOT NULL REFERENCES editions (editionId),
CONSTRAINT pk_oeuvreauteur PRIMARY KEY (oeuvreId, editionId)
);
insert into incorpore values
(1, 1), (2, 2), (3, 3), (4, 4), (4, 5),
(7, 6), (11, 7), (11, 8), (11, 9), (11, 10), (11, 11);
CREATE TABLE exemplaires (
exemplaire_id INTEGER PRIMARY KEY,
edition_id INTEGER REFERENCES editions (edition_id),
exemplaireId INTEGER PRIMARY KEY,
editionId INTEGER REFERENCES editions (edition_id),
date_achat DATE,
prix_achat NUMERIC,
etat TEXT
);
CREATE TABLE relations (
reference_id INTEGER REFERENCES oeuvres (oeuvre_id),
oeuvre_id INTEGER REFERENCES oeuvres (oeuvre_id),
[type] TEXT,
CONSTRAINT pk_relation PRIMARY KEY (reference_id, oeuvre_id)
insert into exemplaires values
(1, 1, '1993-10-30', 22.71, 'bon'),
(2, 2, '1995-02-15', 22.71, 'bon'),
(3, 3, '1996-03-22', 22.71, 'bon'),
(4, 4, '2009-12-22', 15.45, 'bon'),
(5, 5, '2012-09-05', 8.69, 'bon'),
(6, 7, '1993-01-17', 7.50, 'bon'),
(7, 10, '2014-11-05', 8.00, 'bon'),
(8, 11, '2014-09-05', 8.00, 'bon');
-- ************************************************************
CREATE TABLE adherents (
adherentId INTEGER PRIMARY KEY,
prenom TEXT NOT NULL,
nom TEXT NOT NULL,
email TEXT,
naissance DATE,
statutId INTEGER REFERENCES statuts (statutId)
);
CREATE TABLE genres (
genre_id INTEGER PRIMARY KEY,
genre TEXT
);
CREATE TABLE participe (
oeuvre_id INTEGER NOT NULL REFERENCES oeuvres (oeuvre_id),
auteur_id INTEGER NOT NULL REFERENCES auteurs (auteur_id),
fonction TEXT,
alias TEXT
CONSTRAINT pk_oeuvreauteur PRIMARY KEY (oeuvre_id, auteur_id)
);
CREATE TABLE incorpore (
oeuvre_id INTEGER NOT NULL REFERENCES oeuvres (oeuvre_id),
edition_id INTEGER NOT NULL REFERENCES editions (edition_id)
)
CREATE TABLE statuts (
statut_id INTEGER PRIMARY KEY,
statut TEXT
);
CREATE TABLE pays (
pays_id INTEGER PRIMARY KEY,
pays_name TEXT
);
CREATE TABLE adresses (
adresse_id INTEGER PRIMARY KEY,
adresseId INTEGER PRIMARY KEY,
numero TEXT,
voie TEXT,
ville TEXT,
pays_id INTEGER REFERENCES pays (pays_id)
);
CREATE TABLE adherents (
adherent_id INTEGER PRIMARY KEY,
prenom TEXT NOT NULL,
nom TEXT NOT NULL,
email TEXT,
naissance CHAR(10),
statut_id INTEGER,
CONSTRAINT fk_a_statut FOREIGN KEY (statut_id) REFERENCES statuts (statut_id)
CREATE TABLE adherent_adresse (
adherentId INTEGER NOT NULL,
adresseId INTEGER NOT NULL,
statutId INTEGER,
CONSTRAINT pk_adherent_adresse PRIMARY KEY (adherentId, adresseId),
CONSTRAINT fk_aa_adherent FOREIGN KEY (adherentId) REFERENCES adherents (adherentId),
CONSTRAINT fk_aa_adresse FOREIGN KEY (adresseId) REFERENCES adresses (adresseId),
CONSTRAINT fk_aa_statut FOREIGN KEY (statutId) REFERENCES statuts (statutId)
);
CREATE TABLE adherent_adresse (
adherent_id INTEGER NOT NULL,
adresse_id INTEGER NOT NULL,
statut_id INTEGER,
CONSTRAINT pk_adherent_adresse PRIMARY KEY (adherent_id, adresse_id),
CONSTRAINT fk_aa_adherent FOREIGN KEY (adherent_id) REFERENCES adherents (adherent_id),
CONSTRAINT fk_aa_adresse FOREIGN KEY (adresse_id) REFERENCES adresses (adresse_id),
CONSTRAINT fk_aa_statut FOREIGN KEY (statut_id) REFERENCES statuts (statut_id)
);
-- ************************************************************
CREATE TABLE livraison_methode (
methode_id INTEGER PRIMARY KEY,
methodeId INTEGER PRIMARY KEY,
methode_name TEXT,
cout NUMERIC
);
CREATE TABLE commande (
commande_id INTEGER PRIMARY KEY,
commandeId INTEGER PRIMARY KEY,
commande_date DATETIME,
date_echeance DATE,
adherent_id INTEGER REFERENCES adherents (adherent_id),
livraison_methode_id INTEGER REFERENCES livraison_methode (methode_id),
dest_adresse_id INTEGER REFERENCES adresses (adresse_id)
adherentId INTEGER REFERENCES adherents (adherentId),
livraison_methode_id INTEGER REFERENCES livraison_methode (methodeId),
dest_adresseId INTEGER REFERENCES adresses (adresseId)
);
CREATE TABLE commande_statut (
statut_id INTEGER PRIMARY KEY,
statutId INTEGER PRIMARY KEY,
statut_value TEXT
);
CREATE TABLE commande_ligne (
ligne_id INTEGER PRIMARY KEY,
commande_id INTEGER REFERENCES commande (commande_id),
commandeId INTEGER REFERENCES commande (commandeId),
exemplaire_id INTEGER REFERENCES exemplaires (exemplaire_id),
cout NUMERIC,
date_retour DATETIME
@@ -180,9 +259,10 @@ CREATE TABLE commande_ligne (
CREATE TABLE commande_historique (
historique_id INTEGER PRIMARY KEY,
commande_id INTEGER REFERENCES commande (commande_id),
statut_id INTEGER REFERENCES commande_statut (statut_id),
commandeId INTEGER REFERENCES commande (commandeId),
statutId INTEGER REFERENCES commande_statut (statutId),
statut_date DATETIME
);
-- *****
-- ************************************************************