pgtap
This commit is contained in:
83
docker-entrypoint-initdb.d/1_initdb.sql
Normal file
83
docker-entrypoint-initdb.d/1_initdb.sql
Normal file
@@ -0,0 +1,83 @@
|
||||
create extension if not exists ltree;
|
||||
create extension if not exists pgtap;
|
||||
create extension if not exists postgis;
|
||||
create extension if not exists pgrouting;
|
||||
create extension if not exists vector;
|
||||
|
||||
create table adherent (
|
||||
id int primary key,
|
||||
nom text,
|
||||
prenom text,
|
||||
genre smallint,
|
||||
naissance date,
|
||||
codepostal text
|
||||
);
|
||||
|
||||
create table famille (
|
||||
code text primary key,
|
||||
famille text,
|
||||
code_parent text, -- references famille(code)
|
||||
arborescence ltree
|
||||
);
|
||||
|
||||
create table article (
|
||||
code text primary key,
|
||||
article text,
|
||||
famille_code text, -- references famille(code)
|
||||
factpoids boolean,
|
||||
unitevente int,
|
||||
prix decimal,
|
||||
suivistock int
|
||||
);
|
||||
|
||||
create table ticket (
|
||||
id int primary key,
|
||||
date_ticket timestamp,
|
||||
adherent_id int, -- references adherent(id)
|
||||
mode_rglt int
|
||||
);
|
||||
|
||||
create table ligne (
|
||||
id int primary key,
|
||||
ticket_id int, --references ticket (id),
|
||||
article_code text, -- references article (code)
|
||||
prix_unitaire decimal,
|
||||
quantite decimal
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE route (
|
||||
id int primary key,
|
||||
source int,
|
||||
target int,
|
||||
cost double precision,
|
||||
reverse_cost double precision
|
||||
);
|
||||
|
||||
CREATE TABLE produits (
|
||||
id SERIAL PRIMARY KEY,
|
||||
nom TEXT,
|
||||
caracteristiques VECTOR(6)
|
||||
);
|
||||
|
||||
INSERT INTO produits (nom, caracteristiques) VALUES
|
||||
('Tomate', '[0.6, 0.3, 0.3, 1.0, 0.5, 1.0]'),
|
||||
('Concombre', '[0.2, 0.1, 0.9, 1.0, 0.0, 0.0]'),
|
||||
('Courgette', '[0.3, 0.1, 0.5, 1.0, 0.0, 0.0]'),
|
||||
('Carotte', '[0.5, 0.1, 0.8, 0.5, 0.0, 1.0]'),
|
||||
('Poivron', '[0.4, 0.2, 0.6, 1.0, 0.0, 1.0]'),
|
||||
('Aubergine', '[0.2, 0.1, 0.4, 1.0, 0.0, 0.0]'),
|
||||
('Pomme', '[0.8, 0.3, 0.9, 1.0, 1.0, 1.0]'),
|
||||
('Poire', '[0.7, 0.2, 0.7, 1.0, 1.0, 0.0]'),
|
||||
('Fraise', '[0.9, 0.4, 0.7, 1.0, 1.0, 1.0]'),
|
||||
('Cerise', '[0.8, 0.3, 0.6, 1.0, 1.0, 1.0]'),
|
||||
('Citron', '[0.2, 1.0, 0.6, 1.0, 1.0, 1.0]'),
|
||||
('Orange', '[0.7, 0.6, 0.7, 1.0, 1.0, 1.0]'),
|
||||
('Banane', '[0.9, 0.1, 0.2, 1.0, 1.0, 0.0]'),
|
||||
('Raisin', '[0.8, 0.3, 0.5, 1.0, 1.0, 1.0]'),
|
||||
('Pastèque', '[0.8, 0.2, 0.6, 1.0, 1.0, 1.0]'),
|
||||
('Melon', '[0.9, 0.2, 0.5, 1.0, 1.0, 1.0]'),
|
||||
('Betterave', '[0.5, 0.1, 0.4, 0.0, 0.0, 1.0]'),
|
||||
('Radis', '[0.2, 0.3, 0.9, 0.5, 0.0, 1.0]'),
|
||||
('Brocoli', '[0.1, 0.1, 0.6, 0.0, 0.0, 0.0]'),
|
||||
('Chou-fleur', '[0.1, 0.1, 0.7, 0.0, 0.0, 0.0]');
|
||||
11
docker-entrypoint-initdb.d/3_views.sql
Normal file
11
docker-entrypoint-initdb.d/3_views.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
create view nb_total_familles as
|
||||
select count(*) as nb_total_familles from famille;
|
||||
|
||||
create view nb_total_articles as
|
||||
select count(*) as nb_total_articles from article;
|
||||
|
||||
create view nb_total_tickets as
|
||||
select count(*) as nb_total_tickets from ticket;
|
||||
|
||||
create view nb_total_adherents as
|
||||
select count(*) as nb_total_adherents from adherent;
|
||||
28
docker-entrypoint-initdb.d/4_pgtap.sql
Normal file
28
docker-entrypoint-initdb.d/4_pgtap.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
SELECT plan(4);
|
||||
|
||||
SELECT is(
|
||||
(SELECT nb_total_familles FROM nb_total_familles),
|
||||
137::bigint,
|
||||
'La table famille contient 137 enregistrements'
|
||||
);
|
||||
|
||||
SELECT is(
|
||||
(SELECT nb_total_articles FROM nb_total_articles),
|
||||
1099::bigint,
|
||||
'La table article contient 1099 enregistrements'
|
||||
);
|
||||
|
||||
SELECT is(
|
||||
(SELECT nb_total_adherents FROM nb_total_adherents),
|
||||
2439::bigint,
|
||||
'La table adherent contient 2439 enregistrements'
|
||||
);
|
||||
|
||||
SELECT is(
|
||||
(SELECT nb_total_tickets FROM nb_total_tickets),
|
||||
101616::bigint,
|
||||
'La table ticket contient 101 616 enregistrements'
|
||||
);
|
||||
|
||||
-- Termine le test
|
||||
SELECT * FROM finish();
|
||||
@@ -1,42 +0,0 @@
|
||||
create extension if not exists ltree;
|
||||
|
||||
create table adherent (
|
||||
id int primary key,
|
||||
nom text,
|
||||
prenom text,
|
||||
genre smallint,
|
||||
naissance date,
|
||||
codepostal text
|
||||
);
|
||||
|
||||
create table famille (
|
||||
code text primary key,
|
||||
famille text,
|
||||
code_parent text, -- references famille(code)
|
||||
arborescence ltree
|
||||
);
|
||||
|
||||
create table article (
|
||||
code text primary key,
|
||||
article text,
|
||||
famille_code text, -- references famille(code)
|
||||
factpoids boolean,
|
||||
unitevente int,
|
||||
prix decimal,
|
||||
suivistock int
|
||||
);
|
||||
|
||||
create table ticket (
|
||||
id int primary key,
|
||||
date_ticket timestamp,
|
||||
adherent_id int, -- references adherent(id)
|
||||
mode_rglt int
|
||||
);
|
||||
|
||||
create table ligne (
|
||||
id int primary key,
|
||||
ticket_id int, --references ticket (id),
|
||||
article_code text, -- references article (code)
|
||||
prix_unitaire decimal,
|
||||
quantite decimal
|
||||
);
|
||||
Reference in New Issue
Block a user