SQL : upgrade

This commit is contained in:
Dany De Bontridder 2018-02-10 22:42:49 +01:00
parent 26faa009d2
commit 98b5aab93a
14 changed files with 962 additions and 705 deletions

View file

@ -1 +1,12 @@
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
COMMENT ON COLUMN ac_dossier.dos_email IS 'Max emails per day : 0 none , -1 unlimited or max value';
COMMENT ON COLUMN ac_users.use_email IS 'Email of the user';
COMMENT ON TABLE dossier_sent_email IS 'Count the sent email by folder';
COMMENT ON COLUMN dossier_sent_email.id IS 'primary key';
COMMENT ON COLUMN dossier_sent_email.de_date IS 'Date YYYYMMDD';
COMMENT ON COLUMN dossier_sent_email.de_sent_email IS 'Number of sent emails';
COMMENT ON COLUMN dossier_sent_email.dos_id IS 'Link to ac_dossier';
COMMENT ON TABLE user_global_pref IS 'The user''s global parameter ';
COMMENT ON COLUMN user_global_pref.user_id IS 'user''s login ';
COMMENT ON COLUMN user_global_pref.parameter_type IS 'the type of parameter ';
COMMENT ON COLUMN user_global_pref.parameter_value IS 'the value of parameter ';

View file

@ -2,3 +2,44 @@
SET check_function_bodies = false;
SET client_min_messages = warning;
SET search_path = public, pg_catalog;
ALTER TABLE ONLY audit_connect ALTER COLUMN ac_id SET DEFAULT nextval('audit_connect_ac_id_seq'::regclass);
ALTER TABLE ONLY dossier_sent_email ALTER COLUMN id SET DEFAULT nextval('dossier_sent_email_id_seq'::regclass);
ALTER TABLE ONLY ac_dossier
ADD CONSTRAINT ac_dossier_dos_name_key UNIQUE (dos_name);
ALTER TABLE ONLY ac_dossier
ADD CONSTRAINT ac_dossier_pkey PRIMARY KEY (dos_id);
ALTER TABLE ONLY ac_users
ADD CONSTRAINT ac_users_pkey PRIMARY KEY (use_id);
ALTER TABLE ONLY ac_users
ADD CONSTRAINT ac_users_use_login_key UNIQUE (use_login);
ALTER TABLE ONLY audit_connect
ADD CONSTRAINT audit_connect_pkey PRIMARY KEY (ac_id);
ALTER TABLE ONLY dossier_sent_email
ADD CONSTRAINT de_date_dos_id_ux UNIQUE (de_date, dos_id);
ALTER TABLE ONLY dossier_sent_email
ADD CONSTRAINT dossier_sent_email_pkey PRIMARY KEY (id);
ALTER TABLE ONLY jnt_use_dos
ADD CONSTRAINT jnt_use_dos_pkey PRIMARY KEY (jnt_id);
ALTER TABLE ONLY modeledef
ADD CONSTRAINT modeledef_pkey PRIMARY KEY (mod_id);
ALTER TABLE ONLY user_global_pref
ADD CONSTRAINT pk_user_global_pref PRIMARY KEY (user_id, parameter_type);
ALTER TABLE ONLY progress
ADD CONSTRAINT progress_pkey PRIMARY KEY (p_id);
ALTER TABLE ONLY recover_pass
ADD CONSTRAINT recover_pass_pkey PRIMARY KEY (request);
ALTER TABLE ONLY jnt_use_dos
ADD CONSTRAINT use_id_dos_id_uniq UNIQUE (use_id, dos_id);
ALTER TABLE ONLY version
ADD CONSTRAINT version_pkey PRIMARY KEY (val);
ALTER TABLE ONLY recover_pass
ADD CONSTRAINT ac_users_recover_pass_fk FOREIGN KEY (use_id) REFERENCES ac_users(use_id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE ONLY dossier_sent_email
ADD CONSTRAINT de_ac_dossier_fk FOREIGN KEY (dos_id) REFERENCES ac_dossier(dos_id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE ONLY user_global_pref
ADD CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES ac_users(use_login) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE ONLY jnt_use_dos
ADD CONSTRAINT jnt_use_dos_dos_id_fkey FOREIGN KEY (dos_id) REFERENCES ac_dossier(dos_id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE ONLY jnt_use_dos
ADD CONSTRAINT jnt_use_dos_use_id_fkey FOREIGN KEY (use_id) REFERENCES ac_users(use_id);
CREATE TRIGGER limit_user_trg BEFORE INSERT OR UPDATE ON audit_connect FOR EACH ROW EXECUTE PROCEDURE limit_user();

View file

@ -6,3 +6,80 @@ SET check_function_bodies = false;
SET client_min_messages = warning;
INSERT INTO ac_users (use_id, use_first_name, use_name, use_login, use_active, use_pass, use_admin, use_email) VALUES (4, 'demo', 'demo', 'demo', 1, 'fe01ce2a7fbac8fafaed7c982a04e229', 0, NULL);
INSERT INTO ac_users (use_id, use_first_name, use_name, use_login, use_active, use_pass, use_admin, use_email) VALUES (1, NULL, NULL, 'admin', 1, 'b1cc88e1907cde80cb2595fa793b3da9', 1, NULL);
SELECT pg_catalog.setval('audit_connect_ac_id_seq', 1, false);
SELECT pg_catalog.setval('dossier_id', 24, true);
SELECT pg_catalog.setval('dossier_sent_email_id_seq', 1, false);
INSERT INTO modeledef (mod_id, mod_name, mod_desc) VALUES (1, '(BE) Basique', 'Comptabilité Belge, à adapter');
INSERT INTO modeledef (mod_id, mod_name, mod_desc) VALUES (2, '(FR) Basique', 'Comptabilité Française, à adapter');
SELECT pg_catalog.setval('s_modid', 8, true);
SELECT pg_catalog.setval('seq_jnt_use_dos', 28, true);
SELECT pg_catalog.setval('seq_priv_user', 12, true);
INSERT INTO theme (the_name, the_filestyle, the_filebutton) VALUES ('Light', 'style-light.css', NULL);
INSERT INTO theme (the_name, the_filestyle, the_filebutton) VALUES ('Classique', 'style-classic.css', NULL);
INSERT INTO theme (the_name, the_filestyle, the_filebutton) VALUES ('Classic7', 'style-classic7.css', NULL);
INSERT INTO user_global_pref (user_id, parameter_type, parameter_value) VALUES ('demo', 'PAGESIZE', '50');
INSERT INTO user_global_pref (user_id, parameter_type, parameter_value) VALUES ('demo', 'LANG', 'fr_FR.utf8');
INSERT INTO user_global_pref (user_id, parameter_type, parameter_value) VALUES ('admin', 'PAGESIZE', '50');
INSERT INTO user_global_pref (user_id, parameter_type, parameter_value) VALUES ('admin', 'LANG', 'fr_FR.utf8');
INSERT INTO user_global_pref (user_id, parameter_type, parameter_value) VALUES ('admin', 'TOPMENU', 'TEXT');
INSERT INTO user_global_pref (user_id, parameter_type, parameter_value) VALUES ('demo', 'THEME', 'Classic7');
INSERT INTO user_global_pref (user_id, parameter_type, parameter_value) VALUES ('admin', 'THEME', 'Classic7');
SELECT pg_catalog.setval('users_id', 5, true);
INSERT INTO version (val) VALUES (18);

View file

@ -0,0 +1,22 @@
CREATE FUNCTION limit_user() RETURNS trigger
LANGUAGE plpgsql
AS $$
begin
NEW.ac_user := substring(NEW.ac_user from 1 for 80);
return NEW;
end; $$;
CREATE FUNCTION upgrade_repo(p_version integer) RETURNS void
LANGUAGE plpgsql
AS $$
declare
is_mono integer;
begin
select count (*) into is_mono from information_schema.tables where table_name='repo_version';
if is_mono = 1 then
update repo_version set val=p_version;
else
update version set val=p_version;
end if;
end;
$$;

View file

@ -0,0 +1,4 @@
CREATE INDEX audit_connect_ac_user ON audit_connect USING btree (ac_user);
CREATE INDEX fk_jnt_dos_id ON jnt_use_dos USING btree (dos_id);
CREATE INDEX fk_jnt_use_dos ON jnt_use_dos USING btree (use_id);
CREATE INDEX fki_ac_users_recover_pass_fk ON recover_pass USING btree (use_id);

View file

@ -7,6 +7,9 @@
export TEMPLATE=${DOMAIN}account_repository
pg_dump -O -U dany -s $TEMPLATE|grep -v "COMMENT ON SCHEMA public IS 'Standard public schema';" |sed "/^--/d" > schema.sql
sed -i -e "/COMMENT ON EXTENSION/d" schema.sql
sed -i -e "/CREATE EXTENSION/d" schema.sql
awk '/SEQUENCE/,/;/ { print $0;}' < schema.sql > sequence.sql
awk '/CREATE DOMAIN/,/;/ { print $0;}' < schema.sql > table.sql
awk '/CREATE TABLE/,/;/ { print $0;}' < schema.sql >> table.sql

View file

@ -13,6 +13,340 @@ CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
SET search_path = public, pg_catalog;
CREATE FUNCTION limit_user() RETURNS trigger
LANGUAGE plpgsql
AS $$
begin
NEW.ac_user := substring(NEW.ac_user from 1 for 80);
return NEW;
end; $$;
CREATE FUNCTION upgrade_repo(p_version integer) RETURNS void
LANGUAGE plpgsql
AS $$
declare
is_mono integer;
begin
select count (*) into is_mono from information_schema.tables where table_name='repo_version';
if is_mono = 1 then
update repo_version set val=p_version;
else
update version set val=p_version;
end if;
end;
$$;
SET default_tablespace = '';
SET default_with_oids = false;
CREATE TABLE ac_dossier (
dos_id integer DEFAULT nextval(('dossier_id'::text)::regclass) NOT NULL,
dos_name text NOT NULL,
dos_description text,
dos_email integer DEFAULT (-1)
);
COMMENT ON COLUMN ac_dossier.dos_email IS 'Max emails per day : 0 none , -1 unlimited or max value';
CREATE TABLE ac_users (
use_id integer DEFAULT nextval(('users_id'::text)::regclass) NOT NULL,
use_first_name text,
use_name text,
use_login text NOT NULL,
use_active integer DEFAULT 0,
use_pass text,
use_admin integer DEFAULT 0,
use_email text,
CONSTRAINT ac_users_use_active_check CHECK (((use_active = 0) OR (use_active = 1)))
);
COMMENT ON COLUMN ac_users.use_email IS 'Email of the user';
CREATE TABLE audit_connect (
ac_id integer NOT NULL,
ac_user text,
ac_date timestamp without time zone DEFAULT now(),
ac_ip text,
ac_state text,
ac_module text,
ac_url text,
CONSTRAINT valid_state CHECK ((((ac_state = 'FAIL'::text) OR (ac_state = 'SUCCESS'::text)) OR (ac_state = 'AUDIT'::text)))
);
CREATE SEQUENCE audit_connect_ac_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE audit_connect_ac_id_seq OWNED BY audit_connect.ac_id;
CREATE SEQUENCE dossier_id
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE TABLE dossier_sent_email (
id integer NOT NULL,
de_date character varying(8) NOT NULL,
de_sent_email integer NOT NULL,
dos_id integer NOT NULL
);
COMMENT ON TABLE dossier_sent_email IS 'Count the sent email by folder';
COMMENT ON COLUMN dossier_sent_email.id IS 'primary key';
COMMENT ON COLUMN dossier_sent_email.de_date IS 'Date YYYYMMDD';
COMMENT ON COLUMN dossier_sent_email.de_sent_email IS 'Number of sent emails';
COMMENT ON COLUMN dossier_sent_email.dos_id IS 'Link to ac_dossier';
CREATE SEQUENCE dossier_sent_email_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE dossier_sent_email_id_seq OWNED BY dossier_sent_email.id;
CREATE TABLE jnt_use_dos (
jnt_id integer DEFAULT nextval(('seq_jnt_use_dos'::text)::regclass) NOT NULL,
use_id integer NOT NULL,
dos_id integer NOT NULL
);
CREATE TABLE modeledef (
mod_id integer DEFAULT nextval(('s_modid'::text)::regclass) NOT NULL,
mod_name text NOT NULL,
mod_desc text
);
CREATE TABLE progress (
p_id character varying(16) NOT NULL,
p_value numeric(5,2) NOT NULL,
p_created timestamp without time zone DEFAULT now()
);
CREATE TABLE recover_pass (
use_id bigint NOT NULL,
request text NOT NULL,
password text NOT NULL,
created_on timestamp with time zone,
created_host text,
recover_on timestamp with time zone,
recover_by text
);
CREATE SEQUENCE s_modid
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE SEQUENCE seq_jnt_use_dos
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE SEQUENCE seq_priv_user
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE TABLE theme (
the_name text NOT NULL,
the_filestyle text,
the_filebutton text
);
CREATE TABLE user_global_pref (
user_id text NOT NULL,
parameter_type text NOT NULL,
parameter_value text
);
COMMENT ON TABLE user_global_pref IS 'The user''s global parameter ';
COMMENT ON COLUMN user_global_pref.user_id IS 'user''s login ';
COMMENT ON COLUMN user_global_pref.parameter_type IS 'the type of parameter ';
COMMENT ON COLUMN user_global_pref.parameter_value IS 'the value of parameter ';
CREATE SEQUENCE users_id
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE TABLE version (
val integer NOT NULL
);
CREATE INDEX audit_connect_ac_user ON audit_connect USING btree (ac_user);
CREATE INDEX fk_jnt_dos_id ON jnt_use_dos USING btree (dos_id);
CREATE INDEX fk_jnt_use_dos ON jnt_use_dos USING btree (use_id);
CREATE INDEX fki_ac_users_recover_pass_fk ON recover_pass USING btree (use_id);

View file

@ -0,0 +1,44 @@
CREATE SEQUENCE audit_connect_ac_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE audit_connect_ac_id_seq OWNED BY audit_connect.ac_id;
CREATE SEQUENCE dossier_id
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE SEQUENCE dossier_sent_email_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE dossier_sent_email_id_seq OWNED BY dossier_sent_email.id;
CREATE SEQUENCE s_modid
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE SEQUENCE seq_jnt_use_dos
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE SEQUENCE seq_priv_user
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE SEQUENCE users_id
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;

View file

@ -0,0 +1,70 @@
CREATE TABLE ac_dossier (
dos_id integer DEFAULT nextval(('dossier_id'::text)::regclass) NOT NULL,
dos_name text NOT NULL,
dos_description text,
dos_email integer DEFAULT (-1)
);
CREATE TABLE ac_users (
use_id integer DEFAULT nextval(('users_id'::text)::regclass) NOT NULL,
use_first_name text,
use_name text,
use_login text NOT NULL,
use_active integer DEFAULT 0,
use_pass text,
use_admin integer DEFAULT 0,
use_email text,
CONSTRAINT ac_users_use_active_check CHECK (((use_active = 0) OR (use_active = 1)))
);
CREATE TABLE audit_connect (
ac_id integer NOT NULL,
ac_user text,
ac_date timestamp without time zone DEFAULT now(),
ac_ip text,
ac_state text,
ac_module text,
ac_url text,
CONSTRAINT valid_state CHECK ((((ac_state = 'FAIL'::text) OR (ac_state = 'SUCCESS'::text)) OR (ac_state = 'AUDIT'::text)))
);
CREATE TABLE dossier_sent_email (
id integer NOT NULL,
de_date character varying(8) NOT NULL,
de_sent_email integer NOT NULL,
dos_id integer NOT NULL
);
CREATE TABLE jnt_use_dos (
jnt_id integer DEFAULT nextval(('seq_jnt_use_dos'::text)::regclass) NOT NULL,
use_id integer NOT NULL,
dos_id integer NOT NULL
);
CREATE TABLE modeledef (
mod_id integer DEFAULT nextval(('s_modid'::text)::regclass) NOT NULL,
mod_name text NOT NULL,
mod_desc text
);
CREATE TABLE progress (
p_id character varying(16) NOT NULL,
p_value numeric(5,2) NOT NULL,
p_created timestamp without time zone DEFAULT now()
);
CREATE TABLE recover_pass (
use_id bigint NOT NULL,
request text NOT NULL,
password text NOT NULL,
created_on timestamp with time zone,
created_host text,
recover_on timestamp with time zone,
recover_by text
);
CREATE TABLE theme (
the_name text NOT NULL,
the_filestyle text,
the_filebutton text
);
CREATE TABLE user_global_pref (
user_id text NOT NULL,
parameter_type text NOT NULL,
parameter_value text
);
CREATE TABLE version (
val integer NOT NULL
);

View file

@ -1,4 +1,4 @@
set search_path = public, comptaproc,pg_catalog ;
set search_path = public,comptaproc,pg_catalog ;
SET statement_timeout = 0;
SET client_encoding = 'UTF8';
@ -2059,8 +2059,6 @@ SELECT pg_catalog.setval('user_filter_id_seq', 1, false);
INSERT INTO user_local_pref (user_id, parameter_type, parameter_value) VALUES ('1', 'MINIREPORT', '0');
INSERT INTO user_local_pref (user_id, parameter_type, parameter_value) VALUES ('1', 'PERIODE', '79');
@ -2084,8 +2082,8 @@ SELECT pg_catalog.setval('user_sec_action_profile_ua_id_seq', 6, true);
INSERT INTO version (val, v_description, v_date) VALUES (126, NULL, NULL);
INSERT INTO version (val, v_description, v_date) VALUES (127, 'Add filter for search, inactive tag or ledger, type of operation, security', '2018-02-10 22:03:11.229137');
INSERT INTO version (val, v_description, v_date) VALUES (128, 'Add a view to manage VAT', '2018-02-10 22:03:11.584111');
INSERT INTO version (val, v_description, v_date) VALUES (127, 'Add filter for search, inactive tag or ledger, type of operation, security', '2018-02-10 22:35:44.080193');
INSERT INTO version (val, v_description, v_date) VALUES (128, 'Add a view to manage VAT', '2018-02-10 22:35:45.034297');

View file

@ -7,6 +7,8 @@
export TEMPLATE=${DOMAIN}mod1
pg_dump -O -U dany -s $TEMPLATE|grep -v "COMMENT ON SCHEMA public IS 'Standard public schema';" |sed "/^--/d" > schema.sql
sed -i -e "/COMMENT ON EXTENSION/d" schema.sql
sed -i -e "/CREATE EXTENSION/d" schema.sql
awk '/SEQUENCE/,/;/ { print $0;}' < schema.sql > sequence.sql
awk '/CREATE DOMAIN/,/;/ { print $0;}' < schema.sql > table.sql
awk '/CREATE TABLE/,/;/ { print $0;}' < schema.sql >> table.sql

View file

@ -10,7 +10,6 @@ CREATE SCHEMA comptaproc;
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,14 @@
pg_dump -O -U dany -s ${DOMAIN}mod1|grep -v "COMMENT ON SCHEMA public IS 'Standard public schema';" |sed "/^--/d" > schema.sql
#!/bin/bash
# Create script for exporting a new template
# DDB 2018-01-28
# under GPL license
#
export TEMPLATE=${DOMAIN}mod2
pg_dump -O -U dany -s $TEMPLATE|grep -v "COMMENT ON SCHEMA public IS 'Standard public schema';" |sed "/^--/d" > schema.sql
sed -i -e "/COMMENT ON EXTENSION/d" schema.sql
sed -i -e "/CREATE EXTENSION/d" schema.sql
awk '/SEQUENCE/,/;/ { print $0;}' < schema.sql > sequence.sql
awk '/CREATE DOMAIN/,/;/ { print $0;}' < schema.sql > table.sql
awk '/CREATE TABLE/,/;/ { print $0;}' < schema.sql >> table.sql
@ -13,17 +23,20 @@ echo "SET search_path = public, pg_catalog;"
awk '/ALTER TABLE/,/;/ { print $0;}' < schema.sql >> constraint.sql
awk '/CREATE TRIGGER/,/;/ { print $0;}' < schema.sql >> constraint.sql
awk '/COMMENT ON CONSTRAINT/,/;/ { print $0;}' < schema.sql >> constraint.sql
awk '/COMMENT ON TRIGGER/,/;/ { print $0;}' < schema.sql >> constraint.sql
# function in XML
## awk 'BEGIN{print "<PROCEDURES>";} /CREATE FUNCTION/,/\$\$;/ { if (/CREATE FUNCTION/) {print "<procedure>";} if (/\$\$;/) {print "</procedure>";} print $0;} END { print "</PROCEDURES>";}' < schema.sql
awk '/CREATE FUNCTION/,/\$\$;/ { print $0;}' < schema.sql > function.sql
awk '/COMMENT/,/;/ {print $0;}' < schema.sql > comment.sql
sed -i -e "/ALTER TABLE.*/d" -e "/COMMENT ON CONSTRAINT/d" -e "/ADD CONSTRAINT/d" -e "/CREATE PROCEDURAL/d" schema.sql
sed -i -e "/REVOKE /d" -e "/GRANT /d" -e "/ALTER TABLE.*/d" -e "/ADD CONSTRAINT/d" -e "/CREATE PROCEDURAL/d" -e "/CREATE TRIGGER/d" -e "/COMMENT ON CONSTRAINT/d" -e "/COMMENT ON TRIGGER/d" schema.sql
grep setval schema.sql >> sequence.sql
echo "set search_path = public, comptaproc,pg_catalog ;" > data.sql
pg_dump -O -U dany --data-only --column-inserts -O ${DOMAIN}mod1 |sed "/^--/d" | sed -e "/SET search_path/d" >> data.sql
echo "set search_path = public,comptaproc,pg_catalog ;" > data.sql
pg_dump -O -U dany --data-only --column-inserts -O ${TEMPLATE}|sed "/^--/d" | sed -e "/SET search_path/d" >> data.sql