Bonjour la communauté, besoin d'aide. J'ai crée mon projet spring boot. J'aimerai à partir de liquibase générer automatiquement les tables dans la base de données postgresql. Besoin d'aide please.
Voici le contenu de mon fichier application.properties
spring.application.name=gesco
spring.url=jdbc:postgresql://localhost:5432/test
spring.username=postgres
spring.password=postgres
spring.driver-class-name=org.postgresql.Driver
spring.jpa.database=postgresql
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL10Dialect
spring.initialization-mode=ALWAYS
spring.schema=classpath*:database/initDB.sql
#spring.datasource.data=classpath*:database/populateDB.sql
jpa:
hibernate:
ddl-auto: none
liquibase:
change-log: classpath:/changelog/master.xml
Contenu du fichier master.sql
reate table ges_utilisateurs if not exists(
id is not null primary key,
user_nom varchar(100) not null,
user_prenoms varchar(200) not null,
user_username varchar(200) not null,
user_password varchar(100) not null,
user_description varchar(300) not null,
user_telephone varchar(100) not null,
user_adresse varchar(200) not null,
user_signature varchar(200) not null,
user_prenoms varchar(200) not null,
ALTER TABLE ges_utilisateurs ADD CONSTRAINT
fk_address_profils FOREIGN KEY (id_Profils)
REFERENCES utilisateurs.profils (id) ON UPDATE RESTRICT
ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
);
create table ges_profils if not exists(
id is not null primary key,
libellé varchar(100) not null,
description varchar(100) not null,
ALTER TABLE ges_utilisateurs ADD CONSTRAINT
fk_address_utilisateurs FOREIGN KEY (id_utilisateur)
REFERENCES utilisateurs.profils (id) ON UPDATE RESTRICT
ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
);
Contenu de mon fichier maaster.xml
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbch...log-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext
http://www.liquibase.org/xml/ns/dbch...ngelog-ext.xsd
http://www.liquibase.org/xml/ns/pro
http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd">
<changeSet id="100000-1" author="@Esso">
<createTable tableName="ges_utilisateurs">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="user_nom" type="VARCHAR(100 BYTE)"/>
<column name="user_prenoms" type="VARCHAR(200 BYTE)"/>
<column name="user_username" type="VARCHAR(100 BYTE)"/>
<column name="user_password" type="VARCHAR(100 BYTE)"/>
<column name="user_description" type="VARCHAR(300 BYTE)"/>
<column name="user_telephone" type="VARCHAR(100 BYTE)"/>
<column name="user_adresse" type="VARCHAR(200 BYTE)"/>
<column name="user_signature" type="VARCHAR(200 BYTE)"/>
<column name="id_Profils" type="String">
<constraints nullable="false" foreignKeyName="fk_adresse_profils" references="id_profils"/>
</column>
</createTable>
</changeSet>
<changeSet id="100000-2" author="@Esso">
<createTable tableName="ges_profils">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="libellé" type="VARCHAR(100 BYTE)"/>
<column name="description" type="VARCHAR(300 BYTE)"/>
<column name="id_utilisateur" type="String">
<constraints nullable="false" foreignKeyName="fk_adresse_utilisateurs" references="id_utilisateur"/>
</column>
</createTable>
</changeSet>
<include file="changelog/schema.sql" relativeToChangelogFile="true"/>
<include file="changelog/changelog_master.sql" relativeToChangelogFile="true"/>
<include file="changelog/master.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
Contenu du 2è fichier .xml
<?xml version="1.0" encoding="UTF-8" ?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<include file="changelog/changelog_master.xml" />
<include file="changelog/changelog_master.sql" />
<include file="changelog/changelog_master.yml" />
<include file="changelog/schema.sql" />
</databaseChangeLog>
Contenu du 2è fichier .Sql (schema.Sql)
CREATE SCHEMA IF NOT EXISTS liquibase_demo;
Contenu du fichier .yml
## YAML Template.
---
spring:
application:
name: liquibase-service
datasource:
platform: postgres
url: jdbc:postgresql://localhost:5432/poc_db?currentSchema=liquibase_demo
username: postgres
password: postgres
driver-class-name: org.postgresql.Driver
initialization-mode: always
continue-on-error: false
jpa:
properties:
hibernate:
jdbc:
lob:
non_contextual_creation: true
show-sql: true
database: postgresql
database-platform: org.hibernate.dialect.PostgreSQLDialect
open-in-view: false
generate-ddl: false
liquibase:
change-log: classpath:/changelog/changelog_master.xml
default-schema: liquibase_demo
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "maven"
directory: "/"
schedule:
interval: "daily"
databaseChangeLog:
- include:
file: changelog/db.changelog-yaml-changelog_master.yaml
- include:
file: changelog/db.changelog-sql-changelog_master.sql
- include:
file: changelog/db.changelog-json-changelog_master.json
- include:
file: changelog/db.changelog-xml-changelog_master.xml
Merci
Partager