-- om5_RAD
-- ce script permet de créer les tables de parémétrage de gen_plus.class.php

-- SET search_path = om5, public, pg_catalog;

-- tables
INSERT INTO om_droit (om_droit, libelle, om_profil) VALUES
(nextval('om_droit_seq'), 'om_forms', 1);
INSERT INTO om_droit (om_droit, libelle, om_profil) VALUES
(nextval('om_droit_seq'), 'om_tables_parametre', 1);
INSERT INTO om_droit (om_droit, libelle, om_profil) VALUES
(nextval('om_droit_seq'), 'om_actions', 1);
INSERT INTO om_droit (om_droit, libelle, om_profil) VALUES
(nextval('om_droit_seq'), 'om_forms_liste', 1);

-- vues
INSERT INTO om_droit (om_droit, libelle, om_profil) VALUES
(nextval('om_droit_seq'), 'om_tables', 1);
INSERT INTO om_droit (om_droit, libelle, om_profil) VALUES
(nextval('om_droit_seq'), 'om_contraintes', 1);
INSERT INTO om_droit (om_droit, libelle, om_profil) VALUES
(nextval('om_droit_seq'), 'om_vues', 1);
INSERT INTO om_droit (om_droit, libelle, om_profil) VALUES
(nextval('om_droit_seq'), 'om_champs', 1);
INSERT INTO om_droit (om_droit, libelle, om_profil) VALUES
(nextval('om_droit_seq'), 'om_triggers', 1);
INSERT INTO om_droit (om_droit, libelle, om_profil) VALUES
(nextval('om_droit_seq'), 'om_proc', 1);

-- profil hiérarchique

INSERT INTO om_profil (om_profil, libelle, hierarchie) VALUES
(nextval('om_profil_seq'), 'UTILISATEUR', 3);
UPDATE om_profil set hierarchie = 5 where libelle = 'ADMINISTRATEUR';

-- enlever gen


-- tables

CREATE TABLE om_tables_parametre
(
	table_name character varying(40),
    parametres jsonb	
);

CREATE TABLE om_forms
(
  column_name character varying(120),
  parametres jsonb,
  table_name character varying(40)
);
 
CREATE TABLE om_actions(
  om_actions integer not null,
  libelle character varying(40) not null,
  module character varying(40) not null, 
  parametres jsonb,
  table_name character varying(40)
);



-- module édition

--alter table om_etat add column table_name varchar(40);
--alter table om_sousetat add column table_name varchar(40);
--alter table om_requete add column table_name varchar(40);

-- pk

ALTER TABLE ONLY om_tables_parametre
    ADD CONSTRAINT om_tables_parametre_pkey PRIMARY KEY (table_name);

ALTER TABLE ONLY om_forms
    ADD CONSTRAINT om_forms_pkey PRIMARY KEY (column_name);
  
ALTER TABLE ONLY om_actions
    ADD CONSTRAINT om_actions_pkey PRIMARY KEY (om_actions);
 
-- seq

CREATE SEQUENCE om_actions_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


