Table des matières
Installer la base de données
— François Raynaud 2020/06/08 16:29
installation des tables du framework
Il faut modifier le nom du schéma dans data/psql/install.sql et nous allons appeler notre schéma f1 dans la variable schema
/var/www/html/formation/f1/data/pgsql# nano install.sql -- Nom du shéma \set schema 'f1'
Nous allons créer la base formation
/var/www/html/formation/f1/data/pgsql# createdb formation -U postgres
Nous allons installer les tables du framework dans la base formation en utilisant install
/var/www/html/formation/f1/data/pgsql# psql -U postgres formation < install.sql
Les tables du schéma f1 sont les suivantes :
Liste des relations
Schéma | Nom | Type | Propriétaire
--------+-----------------+-------+--------------
f1 | om_collectivite | table | postgres
f1 | om_dashboard | table | postgres
f1 | om_droit | table | postgres
f1 | om_etat | table | postgres
f1 | om_lettretype | table | postgres
f1 | om_logo | table | postgres
f1 | om_parametre | table | postgres
f1 | om_permission | table | postgres
f1 | om_profil | table | postgres
f1 | om_requete | table | postgres
f1 | om_sig_extent | table | postgres
f1 | om_sig_flux | table | postgres
f1 | om_sig_map | table | postgres
f1 | om_sig_map_comp | table | postgres
f1 | om_sig_map_flux | table | postgres
f1 | om_sousetat | table | postgres
f1 | om_utilisateur | table | postgres
f1 | om_widget | table | postgres
18 tables
Installation du lien entre l'application et la base de données
Nous allons créer le répertoire “dyn” et le lien entre l'application et la base de données
Le nom du fichier doit être : database.inc.php
// gestion association
$conn[1] = array(
"Gestion association", // Titre
"pgsql", // Type de base
"pgsql", // Type de base
"postgres", // Login
"postgres", // Mot de passe
"tcp", // Protocole de connexion
"localhost", // Nom d'hote.sql
"5432", // Port du serveur
"", // Socket
"formation", // Nom de la base
"AAAA-MM-JJ", // Format de la date
"f1", // Nom du schéma
"", // Préfixe
null, // Paramétrage pour l'annuaire LDAP
null, // Paramétrage pour le serveur de mail
null, // Paramétrage pour le stockage des fichiers
);
Donner les droits de lecture à www-data (utilisateur apache)
chown -R www-data:www-data /var/www/html/formation/f1
Connexion du framework
Il est possible de se connecter en tapant dans l'url du navigateur http://localhost/formation/f1
Créer les tables de l'application
Dans notre cas nous souhaitons gérer pour les adhérents de notre association les inscriptions et les présences aux conférences par la création dans le fichier init_metier.sql (ou directement dans la base) :
-
des tables de l'application : adherent, conference, adherent_conference
-
des séquences de ces tables
-
des contraintes des clés primaires de ces tables
-
des contraintes de clés secondaires de la table adhérent_conférences
-
des droits dans om_droit pour donner l'accès à l'administrateur
/var/www/html/formation/f1/data/pgsql# nano init_metier.sql
SET search_path = f1, pg_catalog;
CREATE TABLE adherent(
adherent integer NOT NULL,
nom varchar(60) NOT NULL,
prenom varchar(60),
adresse varchar(60),
cp varchar(5),
niveau integer
);
CREATE TABLE conference (
conference integer NOT NULL,
libelle varchar(60) NOT NULL,
date date not null
);
CREATE TABLE adherent_conference(
adherent_conference integer NOT NULL,
adherent integer not null,
conference integer not null,
absent boolean
);
CREATE SEQUENCE adherent_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE SEQUENCE conference_adherent_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE SEQUENCE conference_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- pk
ALTER TABLE ONLY adherent
ADD CONSTRAINT adherent_pkey PRIMARY KEY (adherent);
ALTER TABLE ONLY conference
ADD CONSTRAINT conference_pkey PRIMARY KEY (conference);
ALTER TABLE ONLY adherent_conference
ADD CONSTRAINT adherent_conference_pkey PRIMARY KEY (adherent_conference);
-- fk
ALTER TABLE ONLY adherent_conference
ADD CONSTRAINT adherent_conference_conference_fkey FOREIGN KEY (conference)
REFERENCES conference(conference);
ALTER TABLE ONLY adherent_conference
ADD CONSTRAINT adherent_conference_adherent_fkey FOREIGN KEY (adherent)
REFERENCES adherent(adherent);
-- om_droit
INSERT INTO om_droit (om_droit, libelle, om_profil) VALUES (nextval('om_droit_seq'), 'adherent', 1);
INSERT INTO om_droit (om_droit, libelle, om_profil) VALUES (nextval('om_droit_seq'), 'conference', 1);
INSERT INTO om_droit (om_droit, libelle, om_profil) VALUES (nextval('om_droit_seq'), 'adherent_conference', 1);
Si vous avez créer un fichier init_metier.sql et que vous n'avez pas exécuté ces requêtes dans postgres, nous allons exécuter init_metier.sql dans la base formation :
/var/www/html/formation/f1/data/pgsql# psql -U postgres formation < init_metier.sql
\i init_metier.sql


