Commit fc44ce7e authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Docker stuff

parent 4fb9e346
Loading
Loading
Loading
Loading
+5 −23
Changes for docker-compose.yml: 5 added lines, 23 removed lines.
Original line number Diff line number Diff line
services:
  skeleton-application:
    image: unicaen-db-import-exemple
    build:
      context: .
      args:
        PHP_VERSION: 8.0
    ports:
     - "8080:80"
     - "8443:443"
    volumes:
     - .:/var/www/html
    working_dir: /var/www/html

  db_default:
  db_destination:
    image: postgres:15
    restart: always
    environment:
@@ -22,8 +10,8 @@ services:
    ports:
      - 8432:5432
    volumes:
      - ./data/db_default:/var/lib/postgresql/data
      - ./docker/db_default/:/docker-entrypoint-initdb.d/
      - /tmp/db_destination:/var/lib/postgresql/data
      - ./docker/db/db_destination/:/docker-entrypoint-initdb.d/

  db_source:
    image: postgres:15
@@ -35,11 +23,5 @@ services:
    ports:
      - 9432:5432
    volumes:
      - ./data/db_source:/var/lib/postgresql/data
      - ./docker/db_source/:/docker-entrypoint-initdb.d/

  adminer:
    image: adminer
    restart: always
    ports:
      - 9080:8080
      - /tmp/db_source:/var/lib/postgresql/data
      - ./docker/db/db_source/:/docker-entrypoint-initdb.d/
+68 −0
Changes for docker/db/db_destination/1-unicaen-db-import.sql: 68 added lines, 0 removed lines.
Original line number Diff line number Diff line

create table source
(
    id bigserial not null constraint source_pkey primary key,
    code varchar(64) not null constraint source_code_key unique,
    libelle varchar(128) not null,
    importable boolean not null,
    synchro_insert_enabled boolean default true not null,
    synchro_update_enabled boolean default true not null,
    synchro_undelete_enabled boolean default true not null,
    synchro_delete_enabled boolean default true not null
);
comment on table source is 'Sources de données, importables ou non, ex: Apogée, Physalis.';
comment on column source.importable is 'Indique si cette source de données est importable ou non.';
comment on column source.synchro_insert_enabled is 'Indique si dans le cadre d''une synchro l''opération ''insert'' est autorisée.';
comment on column source.synchro_update_enabled is 'Indique si dans le cadre d''une synchro l''opération ''update'' est autorisée.';
comment on column source.synchro_undelete_enabled is 'Indique si dans le cadre d''une synchro l''opération ''undelete'' est autorisée.';
comment on column source.synchro_delete_enabled is 'Indique si dans le cadre d''une synchro l''opération ''delete'' est autorisée.';

INSERT INTO SOURCE (CODE, LIBELLE, IMPORTABLE) VALUES ('app', 'Application', false);

--
-- Tables nécessaires pour l'observation des synchros.
--
create table IMPORT_OBSERV (
                               ID bigserial not null constraint IMPORT_OBSERV_PK primary key,
                               CODE VARCHAR(50) not null constraint IMPORT_OBSERV_CODE_UN unique,
                               TABLE_NAME VARCHAR(50) not null,
                               COLUMN_NAME VARCHAR(50) not null,
                               OPERATION VARCHAR(50) default 'UPDATE' not null,
                               TO_VALUE VARCHAR(1000),
                               DESCRIPTION VARCHAR(200),
                               ENABLED boolean default false not null,
                               FILTER text,
                               constraint IMPORT_OBSERV_UN unique (TABLE_NAME, COLUMN_NAME, OPERATION, TO_VALUE)
);
create table IMPORT_OBSERV_RESULT (
                                      ID bigserial not null constraint IMPORT_OBSERV_RESULT_PK primary key,
                                      IMPORT_OBSERV_ID integer not null constraint IMPORT_OBSERV_RESULT_IOE_FK references IMPORT_OBSERV on delete cascade,
                                      DATE_CREATION DATE default now() not null,
                                      source_id bigint not null references source(id),
                                      SOURCE_CODE VARCHAR(64) not null,
                                      RESULTAT text not null
);
/*
-- Exemple :
INSERT INTO IMPORT_OBSERV (ID, CODE, TABLE_NAME, COLUMN_NAME, OPERATION, TO_VALUE, FILTER, DESCRIPTION, ENABLED)
VALUES (nextval('IMPORT_OBSERV_ID_SEQ'), 'RESULTAT_PASSE_A_ADMIS', 'THESE', 'RESULTAT', 'UPDATE', '1', 'ETABLISSEMENT_ID IN (SELECT ID FROM ETABLISSEMENT WHERE SOURCE_CODE = ''UCN'')', 'Le résultat de la thèse passe à 1 (admis)', 1);
*/

create table import_log
(
    id bigserial constraint import_log_pkey primary key,
    type varchar(128) not null,
    name varchar(128) not null,
    success boolean not null,
    has_problems boolean default false not null,
    log text not null,
    started_on timestamp not null,
    ended_on timestamp not null,
    import_hash varchar(64)
);

comment on table source is 'Sources de données, importables ou non, ex: Apogée, Physalis.';
comment on column source.synchro_insert_enabled is 'Indique si dans le cadre d''une synchro l''opération ''insert'' est autorisée.';
comment on column source.synchro_update_enabled is 'Indique si dans le cadre d''une synchro l''opération ''update'' est autorisée.';
comment on column source.synchro_undelete_enabled is 'Indique si dans le cadre d''une synchro l''opération ''undelete'' est autorisée.';
comment on column source.synchro_delete_enabled is 'Indique si dans le cadre d''une synchro l''opération ''delete'' est autorisée.';
+111 −0
Changes for docker/db/db_destination/2-schema.sql: 111 added lines, 0 removed lines.
Original line number Diff line number Diff line

--
-- Sources de données à déclarer.
--
insert into source (code, libelle, importable) values ('api_geo', 'API api.geo.gouv.fr', true);
insert into source (code, libelle, importable) values ('db_source', 'Bdd', true);


--
-- Import simple à partir d'une API
--

create table region
(
    id                bigserial               not null        primary key,
    code              varchar(3)              not null        unique,
    nom               varchar(300)            not null,
    --
    source_id             bigint              not null     constraint pays_source_fk     references source,
--     source_code           varchar(64),
    --
    histo_creation        timestamp default now() not null,
    histo_createur_id     bigint                  not null    /*constraint region_hcfk references utilisateur*/,
    histo_modification    timestamp,
    histo_modificateur_id bigint                              /*constraint region_hmfk references utilisateur*/,
    histo_destruction     timestamp,
    histo_destructeur_id  bigint                              /*constraint region_hdfk references utilisateur*/
);


--
-- Import à partir d'une API, et synchro à partir d'une vue de mise en forme (pour calcul de jointure avec 'region')
--

create table tmp_departement
(
    id                bigserial               not null         primary key,
    code              varchar(3)              not null         unique,
    nom               varchar(300)            not null,
    code_region       varchar(3)              not null,
    --
    source_id             bigint              not null     constraint departement_source_fk  references source,
    source_code           varchar(64),
    --
    histo_creation        timestamp default now() not null,
    histo_createur_id     bigint                  not null    /*constraint departement_hcfk references utilisateur*/,
    histo_modification    timestamp,
    histo_modificateur_id bigint                              /*constraint departement_hmfk references utilisateur*/,
    histo_destruction     timestamp,
    histo_destructeur_id  bigint                              /*constraint departement_hdfk references utilisateur*/
);

create view src_departement(id, source_id, code, nom, region_id) as
select null::text as id,
       src.id as source_id,
       tmp.code,
       tmp.nom,
       r.id as region_id
from tmp_departement tmp
    join source src on src.id = tmp.source_id
    join region r on r.code = tmp.code_region;

create table departement
(
    id                    bigserial               not null primary key,
    code                  varchar(3)              not null unique,
    nom                   varchar(300)            not null,
    region_id             bigint                  not null
        constraint departement_region_fk references region on delete cascade,
    --
    source_id             bigint                  not null
        constraint departement_source_fk references source,
    source_code           varchar(64),
    --
    histo_creation        timestamp default now() not null,
    histo_createur_id     bigint                  not null /*constraint departement_hcfk references utilisateur*/,
    histo_modification    timestamp,
    histo_modificateur_id bigint /*constraint departement_hmfk references utilisateur*/,
    histo_destruction     timestamp,
    histo_destructeur_id  bigint /*constraint departement_hdfk references utilisateur*/
);




--
-- Import simple à partir d'une BDD
--
create table pays
(
    id                    bigserial               not null        primary key,
    --code_iso              varchar(3)              not null        unique,
    code_iso_alpha3       varchar(3)              not null        unique,
    --code_iso_alpha2       varchar(2)              not null        unique,
    libelle               varchar(128)            not null,
    libelle_iso           varchar(128)            not null,
    libelle_nationalite   varchar(64),
    --
    libelle_calc          varchar(150),
    --
    source_id             bigint                  not null     constraint pays_source_fk     references source,
--     source_code           varchar(64),
    --
    histo_creation        timestamp default now() not null,
    histo_createur_id     bigint                  not null    /*constraint pays_hcfk references utilisateur*/,
    histo_modification    timestamp,
    histo_modificateur_id bigint                              /*constraint pays_hmfk references utilisateur*/,
    histo_destruction     timestamp,
    histo_destructeur_id  bigint                              /*constraint pays_hdfk references utilisateur*/
);
+260 −0

File added.

Preview size limit exceeded, changes collapsed.