From 68144c3918e84404ae2404c12b422dc2c1bd8971 Mon Sep 17 00:00:00 2001 From: medina5 Date: Mon, 1 Sep 2025 07:56:13 +0200 Subject: [PATCH] pgtap --- Dockerfile | 86 ++++++++++++++++++- README.md | 18 ++-- compose.yaml | 2 +- data/article.csv | 78 ++++++++--------- data/famille.csv | 2 +- docker-entrypoint-initdb.d/1_initdb.sql | 83 ++++++++++++++++++ .../{seed.sql => 2_seed.sql} | 0 docker-entrypoint-initdb.d/3_views.sql | 11 +++ docker-entrypoint-initdb.d/4_pgtap.sql | 28 ++++++ docker-entrypoint-initdb.d/initdb.sql | 42 --------- 10 files changed, 257 insertions(+), 93 deletions(-) create mode 100644 docker-entrypoint-initdb.d/1_initdb.sql rename docker-entrypoint-initdb.d/{seed.sql => 2_seed.sql} (100%) create mode 100644 docker-entrypoint-initdb.d/3_views.sql create mode 100644 docker-entrypoint-initdb.d/4_pgtap.sql delete mode 100644 docker-entrypoint-initdb.d/initdb.sql diff --git a/Dockerfile b/Dockerfile index 2aae2f8..0cf3f10 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,28 @@ +FROM debian:trixie AS build-essential + +RUN set -eux; \ + apt-get update; \ + apt-get upgrade -y + +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + build-essential \ + cmake \ + checkinstall \ + ; + +FROM build-essential AS build-pgdev + +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + postgresql-server-dev-17 \ + ; + + # Étape 1 : builder temporaire pour compiler pgTAP -FROM debian:trixie AS builder +FROM debian:trixie AS pgTAP # Installer les outils nécessaires pour compiler pgTAP RUN apt-get update && \ @@ -16,7 +39,55 @@ RUN git clone --depth 1 https://github.com/theory/pgtap.git /usr/src/pgtap && \ make && \ make install DESTDIR=/pgtap-dist -# Étape 2 : image finale PostgreSQL propre +# ============================================================================= +# pgRouting +FROM build-pgdev AS pgrouting + +ARG pgrouting_release=3.8.0 + +ADD "https://github.com/pgRouting/pgrouting/releases/download/v${pgrouting_release}/pgrouting-${pgrouting_release}.tar.gz" \ + /tmp/pgrouting.tar.gz + +RUN set -eux; \ + tar -xvf /tmp/pgrouting.tar.gz -C /tmp; \ + rm -rf /tmp/pgrouting.tar.gz; + +# Installer les dépendances de compilation +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + libboost-all-dev \ + ; + +WORKDIR /tmp/pgrouting-${pgrouting_release}/build +RUN cmake -DBUILD_HTML=OFF -DBUILD_DOXY=OFF .. + +# Create debian package +RUN checkinstall -D --install=no --fstrans=no --backup=no --pakdir=/tmp \ + --pkgname=pgrouting --pkgversion=${pgrouting_release} \ + --nodoc + +# ============================================================================= +# pgVector +FROM build-pgdev AS pgvector + +ARG pgvector_release=0.6.2 + +ADD "https://github.com/pgvector/pgvector/archive/refs/tags/v${pgvector_release}.tar.gz" \ + /tmp/pgvector.tar.gz + +RUN tar -xvf /tmp/pgvector.tar.gz -C /tmp && \ + rm -rf /tmp/pgvector.tar.gz + +# Build from source +WORKDIR /tmp/pgvector-${pgvector_release} +RUN make -j$(nproc) + +# Create debian package +RUN checkinstall -D --install=no --fstrans=no --backup=no --pakdir=/tmp \ + --nodoc + +# Étape 3 : image finale PostgreSQL propre FROM postgres:17.6 RUN set -eux; \ @@ -37,4 +108,13 @@ RUN set -eux; \ postgresql-postgis # Copier uniquement les fichiers installés depuis le builder -COPY --from=builder /pgtap-dist/ / +COPY --from=pgTAP /pgtap-dist/ / + +COPY --from=pgrouting /tmp/*.deb /tmp +COPY --from=pgvector /tmp/*.deb /tmp + +RUN set -eux; \ + apt-get install \ + /tmp/*.deb \ + -y; \ + rm /tmp/*.deb; diff --git a/README.md b/README.md index 5975702..1a388e7 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,19 @@ docker build -t iut/pgsql:2025-08 . ## Données +### Conventions de nommage + +Le nom des tables est au singulier et en minuscule + ### Schéma -``` -Adherent : id, nom, prenom, genre, naissance, codepostal -Famille : code, famille, code_parent -Article : code, article, famille_code, factpoids, prix -Ticket : id, date_ticket, adherent_id, mode_rglt -Ligne : id, ticket_id, article_code, prix_unitaire, quantite -``` +table |colonnes +--- |--- +adherent | id, nom, prenom, genre, naissance, codepostal +famille | code, famille, code_parent +article | code, article, famille_code, factpoids, prix +ticket | id, date_ticket, adherent_id, mode_rglt +ligne | id, ticket_id, article_code, prix_unitaire, quantite ### Export diff --git a/compose.yaml b/compose.yaml index 9e74aa1..ec658d6 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,6 +1,6 @@ services: database: - image: iut/pgsql:2025-08 + image: iut/pgsql:2025-09 environment: POSTGRES_INITDB_ARGS: "--locale-provider=icu --icu-locale=fr-FR" POSTGRES_DB: ${COMPOSE_PROJECT_NAME} diff --git a/data/article.csv b/data/article.csv index 55678ee..1d8fc7c 100644 --- a/data/article.csv +++ b/data/article.csv @@ -272,7 +272,7 @@ CONCOM,Concombre Noa Jardins,02CONC,t,3,3.5,0 CONCOMSCOT,Concombre long FR,02CONC,f,2,1.9,0 CONFITUREC,Confiture en pot 370g,12,f,1,5,0 CONSOUDE,Consoude officinale Bio Plant,05AROM,f,2,2.3,0 -COOKIEEPEAUTRE300,Cookies Epeautre 300 gr,12PROVINCE,f,1,6.7,0 +COOKIEEPEAUTRE300,Cookies Epeautre 300 gr,04PA,f,1,6.7,0 CORI,Coriandre Bio Plant,05AROM,f,2,2.3,0 CORIAND,Coriande bouquet,02AROM,f,1,1.4,0 CORIANDRADESCOT,Coriandrade 100g,04MOUT,f,1,4.3,0 @@ -509,10 +509,10 @@ LENTBELUGA,lentille beluga 500 g,04LENT,f,1,3.45,2 LENTIL,Lentillons 500 g,04LENT,f,2,3.15,2 LENTILLEBELUGAKG,Lentilles Beluga Kg,04CEREALE,t,3,4.5,0 LENTILLECORAIL,Lentille Corail Vrac,04CEREALE,t,3,4.5,2 -LENTILVERT,Lentilles vertes 1kg,12PROVINCE,f,1,5.5,0 +LENTILVERT,Lentilles vertes 1kg,04LENT,f,1,5.5,0 LENTILVERTE,Lentilles vertes 500 gr,04LENT,f,1,3.3,2 -LENTKG,Lentilles Vrac,12PROVINCE,t,3,4.2,0 -LENTVERT5,Lentilles vertes 500g,12PROVINCE,f,1,3,0 +LENTKG,Lentilles Vrac,04LENT,t,3,4.2,0 +LENTVERT5,Lentilles vertes 500g,04LENT,f,1,3,0 LEVURE,Saf-Levure Boite 125g,04MOUT,f,1,1.7,2 LIN,Lin brun kg,04CEREALE,t,3,3.8,2 LITCHI,Litchi Madagascar,03EXOTIQ,t,3,12.45,2 @@ -539,7 +539,7 @@ MAQUEREAUSM,Maquereaux moutarde 113g,04POIS,f,1,3.4,2 MAQVINBLANC,Maquereaux au vin blanc,04POIS,f,1,3.1,2 MARACU,Maracuja Ouganda,03CHERI,t,3,19.5,2 MARJO,Marjolaine Plant,05AROM,f,2,2.3,0 -MARJOL,Marjolaine Bio Plant,05AROM2,f,2,2.3,0 +MARJOL,Marjolaine Bio Plant,05AROMCH,f,2,2.3,0 MARRON,Marron d'Ardèche,03FS,t,3,9.05,2 MARRONENTIERVAP,Marron entier Cuit Vapeur 200g,03FS,f,1,4.2,2 MARRONPRECUIT,Marron pré-cuit France,03FS,f,2,4,2 @@ -551,7 +551,7 @@ MELANGE,Mélange Fleurs semences,05SEME,f,1,2,0 MELCHAMPI,Mélange champignons,02CHAM,t,3,7,0 MELFRUISEC,Melange pom poir mang bana,03FS,t,3,25,2 MELGATEAU,Melange gateau 30g,12ARTISMON,f,2,2.4,0 -MELISSE,Mélisse Bio Plant,05AROM2,f,2,2.3,0 +MELISSE,Mélisse Bio Plant,05AROMCH,f,2,2.3,0 MELOGAL,Melon Galia Espagne,03MELON,t,3,2.9,2 MELON,Melon Charentais France,03MELON,t,3,3.5,2 MELONCAN,Melon Cantaloup Italie kg,03MELON,t,3,2.5,2 @@ -561,14 +561,14 @@ MELONPO,Melon Porto France,03MELON,t,3,2.9,2 MELPLT,Melon Bio Plant,05MELON,f,2,2.2,0 MELWOKEPIC,Mélange wok épicé,15TRANSLEG,t,3,14,0 MELWOKNAT,Mélange wok nature,15TRANSLEG,t,3,12,0 -MEMA,Menthe marocaine Bio Plant,05AROM2,f,2,2.3,0 -MENCH,Menthe chocolat Plant,05AROM2,f,2,2.3,0 -MENMA,Menthe Pomme Plant,11MENTHE,f,2,2,0 +MEMA,Menthe marocaine Bio Plant,05AROMCH,f,2,2.3,0 +MENCH,Menthe chocolat Plant,05AROMCH,f,2,2.3,0 +MENMA,Plant Menthe Pomme,11MENTHE,f,2,2,0 MENSPI,Menthe spicata Plant,05AROM,f,2,2,0 MENTHE,Menthe,02AROM,f,2,1.2,0 -MENTORA,Menthe orange Bio Plant,05AROM2,f,2,2.3,0 -MENTPOM,Menthe pomme Bio Plant,05AROM2,f,2,2.3,0 -MEPO,Menthe poivrée Plant,05AROM2,f,2,2.3,0 +MENTORA,Menthe orange Bio Plant,05AROMCH,f,2,2.3,0 +MENTPOM,Menthe pomme Bio Plant,05AROMCH,f,2,2.3,0 +MEPO,Menthe poivrée Plant,05AROMCH,f,2,2.3,0 MERI,Meringue sachet,04PA,f,2,1.2,2 MESCLU,Mesclun de chou asiatique,02SALA,t,3,13,0 MESCLUN,Mesclun,02SALA,t,3,5,0 @@ -668,24 +668,24 @@ ORANWAS,Orange Afrique Sud,03ORANGE,t,3,4.95,2 ORAOVALI,Orange Valancia Italie,03ORANGE,t,3,2,2 ORASALA,Orange à jus kg Espagne,03ORANGE,t,3,2.2,2 ORIG,Origan Plant,05AROM,f,2,2,0 -ORIGA,Origan Bio Plant,05AROM2,f,2,2.3,0 +ORIGA,Origan Bio Plant,05AROMCH,f,2,2.3,0 ORIGAN,Origan vulgaire Plant,05AROM,f,2,2,0 ORMALTA,Orange maltaise tarocco Italie,03ORANGE,t,3,2.8,2 ORTILLETTE33,Ortillette 33cl,04BOISSONS,f,2,2.6,2 ORTILLETTE75,Ortillette 75cl,04BOISSONS,f,2,4.9,2 -OSEILLE,Oseille Bio Plant,05AROM2,f,2,2.3,0 -OSEILPOU,Oseille pourpre Bio Plant,05AROM2,f,2,2.3,0 +OSEILLE,Oseille Bio Plant,05AROMCH,f,2,2.3,0 +OSEILPOU,Oseille pourpre Bio Plant,05AROMCH,f,2,2.3,0 OSTARA,pomme ostara,02POMM,t,3,1.5,0 P4GR05,Pain 4 graines 500 g,04PA,f,2,3.1,2 PAINB,Pain blé moulé 750g,04PA,f,2,2.9,2 PAINBLE,Pain soldé,04PA,f,2,1,2 -PAINBLECOMPLET500,Complet Blé 500g,12PROVINCE,f,1,3.5,0 -PAINBLEDEMICOM500,Semi-complet Blé 500g,12PROVINCE,f,2,3.3,0 -PAINBLEMULTIGR500,Multi-graines 500g,12PROVINCE,f,1,4.5,0 -PAINBLENOIX500,Noix 500g,12PROVINCE,f,1,4.8,0 -PAINBLERAISIN500,Raisins Pain 500g,12PROVINCE,f,1,4.5,0 +PAINBLECOMPLET500,Complet Blé 500g,04PA,f,1,3.5,0 +PAINBLEDEMICOM500,Semi-complet Blé 500g,04PA,f,2,3.3,0 +PAINBLEMULTIGR500,Multi-graines 500g,04PA,f,1,4.5,0 +PAINBLENOIX500,Noix 500g,04PA,f,1,4.8,0 +PAINBLERAISIN500,Raisins Pain 500g,04PA,f,1,4.5,0 PAINEP,Pain de vieilles variétés 500g,04PA,f,2,2.9,2 -PAINEPEAUTRE500,Epeautre 500g,12PROVINCE,f,1,4.8,0 +PAINEPEAUTRE500,Epeautre 500g,04PA,f,1,4.8,0 PAINEPICE,Pain d'épices nature fermier 350g,04PA,f,1,7.9,2 PAINEPICECHOCO,Pain d'épices chocolat orange 350g,04PA,f,1,8.4,2 PAINEPICENAT,Pain d'épice nature,12ARTISMON,f,2,5.6,0 @@ -695,10 +695,10 @@ PAINFLEURSSANSSEL,Pain Fleurs Ss Sel Ss Gluten 150g,04PA,f,1,3,2 PAINMI,Pain de mie 500 g,04PA,f,2,3.6,2 PAINNOIX,Pain aux noix 500g,04PA,f,1,3.1,2 PAINOI,Pain aux graines courge 500g,04PA,f,2,3.1,2 -PAINPETEPEAUTRE500,Petit Epeautre 500g,12PROVINCE,f,1,6.2,0 +PAINPETEPEAUTRE500,Petit Epeautre 500g,04PA,f,1,6.2,0 PAINS,Salade Pain de sucre kg,02SALA,t,3,3.5,0 -PAINSARRASINRIZ400,Sarrasin Riz 400g,12PROVINCE,f,1,4.6,0 -PAINSEIGLE500,Seigle 500g,12PROVINCE,f,1,3.9,0 +PAINSARRASINRIZ400,Sarrasin Riz 400g,04PA,f,1,4.6,0 +PAINSEIGLE500,Seigle 500g,04PA,f,1,3.9,0 PAIRAI,Pain aux raisins 500g,04PA,f,2,3.1,2 PAMAN,Poudre d'amande vrac,03FS,t,3,18.3,2 PANAIS,Panais Jardins,02PANA,t,3,3.3,0 @@ -750,9 +750,9 @@ PECHESBARQUETTE,Barquette de pêches,03PECHE,f,1,2.9,2 PECHJ,Pêche plate france,03PECHE,t,3,7.75,2 PECHJA,Pêche de vigne,03PECHE,t,3,6.7,2 PECPLA,Pêche Sanguine,03PECHE,t,3,7.55,2 -PEFR,Persil frisé Bio Plant,05AROM2,f,2,2.3,0 +PEFR,Persil frisé Bio Plant,05AROMCH,f,2,2.3,0 PEPE05,Epeautre 500 g,04PA,f,2,3.2,2 -PEPL,Persil plat Bio Plant,05AROM2,f,2,2.3,0 +PEPL,Persil plat Bio Plant,05AROMCH,f,2,2.3,0 PEPOIS,Petit pois Jardins,02POIS,t,3,8,0 PERSIL,Persil vrac,02AROM,t,3,28,0 PERSILFR,Persil Bouquet,02AROM,f,2,1,2 @@ -766,7 +766,7 @@ PHYSABQ,Physalis Jardins,03CHERI,t,3,11,2 PHYSALIS,Physalis Bio Plant,05PLANT,f,2,2.3,0 PIGNON,Pignons de Pin Espagne,03FS,f,1,17.3,2 PIMENT,Piment Bio Plant,05SOLAN,f,2,1.5,0 -PIMPREN,Pimprenelle Bio Plant,05AROM2,f,2,2.3,0 +PIMPREN,Pimprenelle Bio Plant,05AROMCH,f,2,2.3,0 PISSEN,Pissenlit,02SALA,t,3,18,0 PISTA,Pistache déc.vrac Italie,03FS,t,3,63,2 PISTA250,Pistache décortiquée 250 grs,03FS,f,2,14.55,2 @@ -896,7 +896,7 @@ RAICHAS,Raisin blanc Chasselas France,03RAISIN,t,3,6.75,2 RAICHRO,Raisin rosé Chasselas France,03RAISIN,t,3,6.7,2 RAICLA,Raisin blanc vittoria italie,03RAISIN,t,3,4.3,2 RAIDANFR,Raisin blanc Danlas France,03RAISIN,t,3,6,2 -RAIFO,Raifort Bio Plant,05AROM2,f,2,2.3,0 +RAIFO,Raifort Bio Plant,05AROMCH,f,2,2.3,0 RAIITA,raisin exalta sans pépins France,03RAISIN,t,3,6.95,2 RAILAV,Raisin Lavallée Noir,03RAISIN,t,3,6.2,2 RAILIV,Raisin muscat noir,03RAISIN,t,3,7.3,2 @@ -931,12 +931,12 @@ RIZLON,Riz long blanc thai vrac,04CEREALE,t,3,4.5,2 RIZTHAIJASMB,Riz thai jasmin blanc 500g,12ARTISMON,f,2,3.05,0 RIZTHAIJASMC,Riz thai jasmin complet 500g,12ARTISMON,f,2,2.75,0 RIZTRIOCAMARGUE,Riz Trio Camargue Vrac,04CEREALE,t,3,6.7,2 -ROMA,Romarin Bio Plant,05AROM2,f,2,2.3,0 +ROMA,Romarin Bio Plant,05AROMCH,f,2,2.3,0 ROOIBOS,Rooibos afrique super fruit 80g,12ARTISMON,f,2,6.4,0 ROQU,Roquette poids,02SALA,t,3,6,0 ROQUE,Roquette sauvage Plant,05AROM,f,2,2,0 ROQUEFORT,Roquefort papillon,04FROMAGE,f,2,3.95,2 -ROQUEPL,Roquette Bio Plant,05AROM2,f,2,2.3,0 +ROQUEPL,Roquette Bio Plant,05AROMCH,f,2,2.3,0 ROQUET,Roquette,02SALA,t,3,12,0 ROULEAUPRINTEMPS,Rouleau de Printemps Kg,15TRANSLEG,t,3,20,0 RUTABA,Rutabaga Jardins,02NARU,t,3,2.6,0 @@ -974,9 +974,9 @@ SARDINECITRON,Sardines à l'huile et citron 220g,04POIS,f,1,7.95,0 SARDINEHUILEOLIV,Sardines à l'huile d'olives 220g,04POIS,f,1,7.95,0 SARDINEPIMENTESP,Sardines à l'huile d'olive et piment d'espelette 220g AOP,04POIS,f,1,7.95,0 SARHOC,Sardine à l'huile d'olive citron 135g,04POIS,f,1,3.55,0 -SARIE,Sariette vivace Bio Plant,05AROM2,f,2,2.3,0 -SAUG,Sauge officinale Plant,05AROM2,f,2,2.3,0 -SAUGANA,Sauge ananas Bio Plant,05AROM2,f,2,2.3,0 +SARIE,Sariette vivace Bio Plant,05AROMCH,f,2,2.3,0 +SAUG,Sauge officinale Plant,05AROMCH,f,2,2.3,0 +SAUGANA,Sauge ananas Bio Plant,05AROMCH,f,2,2.3,0 SAUGE,Sauge bouquet,02AROM,f,2,1.4,0 SAUPOU,Sauge Pourpre Plant,05AROM,f,2,2,0 SCAFRI,Scarole Frisée,02SALA,f,2,1.5,0 @@ -1031,11 +1031,11 @@ THON,Thon au naturel 400g,04THON,f,2,8.95,2 THONAT,Thon au naturel 160g,04THON,f,1,4.05,2 THONHUI,Thon huile olive 160g,04THON,f,1,6.2,2 THY,Thym bouquet,02AROM,f,2,1.4,0 -THYM,Thym commun Bio Plant,05AROM2,f,2,2.3,0 -THYMCI,Thym citron Bio Plant,05AROM2,f,2,2.3,0 -THYMCIT,Thym citron panaché Bio Plant,05AROM2,f,2,2.3,0 +THYM,Thym commun Bio Plant,05AROMCH,f,2,2.3,0 +THYMCI,Thym citron Bio Plant,05AROMCH,f,2,2.3,0 +THYMCIT,Thym citron panaché Bio Plant,05AROMCH,f,2,2.3,0 THYMOR,Thym Orange Plant,05AROM,f,2,2,0 -THYMORANGE,Thym orange Bio Plant,05AROM2,f,2,2.3,0 +THYMORANGE,Thym orange Bio Plant,05AROMCH,f,2,2.3,0 THYMVU,Thym vulgaris gold Plant,05AROM,f,2,2,0 TISANEVERVEINE,Tisane Verveine sachet,04TISANE,f,1,4.5,0 TOAN,Ananas Bio Plant,05TOMA,f,2,1.6,0 @@ -1079,10 +1079,10 @@ TOZEB,Green Zebra Bio Plant,05TOMA,f,2,1.6,0 TROISBAIESARCADIE,Trois Baies Arcadie 70 gr,04MOUT,f,1,7.5,0 TRUFPRALIN,Truffes pralinées 100g,12ARTISMON,f,2,4.95,0 TULIPEBOUQUET,Tulipe en bouquet,05PL,f,2,5,0 -VALERIANE,Valériane officinale Bio Plant,05AROM2,f,2,2.3,0 +VALERIANE,Valériane officinale Bio Plant,05AROMCH,f,2,2.3,0 VEGANSPRITCOCO,Vegan spritz coco choco ss gluten,04CONFISER,f,2,3.95,2 VENTRECHETHONHUILE,Ventreche de Thon Albacore à l'huile d'olive 210g,04POIS,f,1,9.9,0 -VERV,Verveine Citronnelle Plant,05AROM2,f,2,2.3,0 +VERV,Verveine Citronnelle Plant,05AROMCH,f,2,2.3,0 VINABAL,Vinaigre Balsamique 250 ml,04VINAIGRE,f,2,4.3,2 VINAFLOMIEL,Vinaigre floramiel 25cl,04VINAIGRE,f,2,4.5,2 VINAIGCIDRECOT,Vinaigre de cidre coteaux 75cl,04VINAIGRE,f,2,3.25,2 diff --git a/data/famille.csv b/data/famille.csv index 7e41d8b..e7652d8 100644 --- a/data/famille.csv +++ b/data/famille.csv @@ -126,7 +126,7 @@ code,famille,code_parent,arborescence 05TOMA,Tomate,05PLANT,Jardin.Plants.Tomate 06,** PRESTATIONS,,Jardin.Prestations 06PE,Prestations environnements,06,Jardin.Prestations.Environnement -O5AROM,** PLANTS Aromates,05PLANT,Jardin.Plants.Aromates +05AROM,** PLANTS Aromates,05PLANT,Jardin.Plants.Aromates 05AROMAB,Aromates A - B,05AROM,Jardin.Plants.Aromates.AB 05AROMCH,Aromates C - H,05AROM,Jardin.Plants.Aromates.CH 12,** Producteurs,,Jardin.Producteurs diff --git a/docker-entrypoint-initdb.d/1_initdb.sql b/docker-entrypoint-initdb.d/1_initdb.sql new file mode 100644 index 0000000..3403563 --- /dev/null +++ b/docker-entrypoint-initdb.d/1_initdb.sql @@ -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]'); diff --git a/docker-entrypoint-initdb.d/seed.sql b/docker-entrypoint-initdb.d/2_seed.sql similarity index 100% rename from docker-entrypoint-initdb.d/seed.sql rename to docker-entrypoint-initdb.d/2_seed.sql diff --git a/docker-entrypoint-initdb.d/3_views.sql b/docker-entrypoint-initdb.d/3_views.sql new file mode 100644 index 0000000..08e8e3c --- /dev/null +++ b/docker-entrypoint-initdb.d/3_views.sql @@ -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; diff --git a/docker-entrypoint-initdb.d/4_pgtap.sql b/docker-entrypoint-initdb.d/4_pgtap.sql new file mode 100644 index 0000000..f90fe90 --- /dev/null +++ b/docker-entrypoint-initdb.d/4_pgtap.sql @@ -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(); diff --git a/docker-entrypoint-initdb.d/initdb.sql b/docker-entrypoint-initdb.d/initdb.sql deleted file mode 100644 index d6685b3..0000000 --- a/docker-entrypoint-initdb.d/initdb.sql +++ /dev/null @@ -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 -);