Files
sql/docker-entrypoint-initdb.d/1_initdb.sql
2025-09-17 00:39:54 +02:00

89 lines
2.0 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 pgcrypto;
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
);
alter table ligne
add column total decimal generated always as (prix_unitaire * quantite) stored;
create table marque (
id int primary key,
marque text not null
);
create table fournisseur (
id int primary key,
fournisseur text not null
);
create table region (
id int primary key,
region text not null
);
insert into region values
(1, 'Est'), (2, 'Ouest');
-- Apache Superset
create database superset;
create user superset with password 'supermotdepasse';
grant all privileges on database superset to superset;
grant connect on database sql to superset;
grant usage on schema public to superset;
grant select on table famille, article to superset;
-- Pour toutes les tables dun schéma existant
grant select on all tables in schema public to superset;
-- Privilège par défaut pour que chaque nouvelle table créée dans public donnera automatiquement le droit SELECT à superset.
alter default privileges in schema public
grant select on tables to superset;
\c superset
alter schema public owner to superset;
grant all privileges on schema public to superset;