Skip to content

Commit ffb9cc1

Browse files
Use liquibase (#20)
1 parent 9fe058f commit ffb9cc1

File tree

7 files changed

+263
-10
lines changed

7 files changed

+263
-10
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33

44
To automatically generate the sql schema file you can use the following command:
55

6-
mvn package -DskipTests && rm src/main/resources/mappings.sql && java -jar target/gridsuite-mapping-server-1.0.0-SNAPSHOT-exec.jar --spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create
6+
Please read [liquibase usage](https://github.com/powsybl/powsybl-parent/#liquibase-usage) for instructions to automatically generate changesets.
7+
After you generated a changeset do not forget to add it to git and in src/resource/db/changelog/db.changelog-master.yml
8+
79

810
Parameters are not yet generated by the app. For now the app will not work as intended without any data.
911

10-
After creating the database and its tables, load **src/main/resources/IEEE14Models.sql** to instantiate some.
12+
After creating the database and its tables, load **src/main/resources/IEEE14Models.sql** to instantiate some.
13+
14+
The old way to automatically generate the sql schema file (directly using hibernate) can still be used for debugging. Use the following command:
15+
```
16+
mvn package -DskipTests && rm src/main/resources/mappings.sql && java -jar target/gridsuite-mapping-server-1.0.0-SNAPSHOT-exec.jar --spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create
17+
```

pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<parent>
1515
<groupId>com.powsybl</groupId>
1616
<artifactId>powsybl-parent-ws</artifactId>
17-
<version>4</version>
17+
<version>6</version>
1818
<relativePath/>
1919
</parent>
2020

@@ -39,6 +39,7 @@
3939
<string-template.version>4.3.1</string-template.version>
4040
<commons-lang3.version>3.9</commons-lang3.version>
4141
<jib.container.environment>SPRING_PROFILES_ACTIVE=default</jib.container.environment>
42+
<liquibase-hibernate-package>org.gridsuite.mapping.server</liquibase-hibernate-package>
4243
</properties>
4344

4445
<build>
@@ -158,6 +159,12 @@
158159
<artifactId>postgresql</artifactId>
159160
<scope>runtime</scope>
160161
</dependency>
162+
<dependency>
163+
<groupId>org.liquibase</groupId>
164+
<artifactId>liquibase-core</artifactId>
165+
<scope>runtime</scope>
166+
</dependency>
167+
161168
<!-- Test dependencies -->
162169
<dependency>
163170
<groupId>com.powsybl</groupId>

src/main/java/org/gridsuite/mapping/server/model/ScriptEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class ScriptEntity extends AbstractManuallyAssignedIdentifierEntity<Strin
3131
@Column(name = "parent", nullable = true)
3232
private String parentName;
3333

34-
@Column(name = "script", nullable = false, columnDefinition = "TEXT")
34+
@Column(name = "script", nullable = false, columnDefinition = "CLOB")
3535
private String script;
3636

3737
@Override
@@ -42,7 +42,7 @@ public String getId() {
4242
@Column(name = "created_date")
4343
private Date createdDate;
4444

45-
@Column(name = "parameters_file", nullable = true, columnDefinition = "TEXT")
45+
@Column(name = "parameters_file", nullable = true, columnDefinition = "CLOB")
4646
private String parametersFile;
4747

4848
public ScriptEntity(String name, ScriptEntity scriptToCopy) {

src/main/resources/application.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ spring:
1919
database: POSTGRESQL
2020
hibernate:
2121
ddl-auto: validate
22-
naming:
23-
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
24-
implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
2522
properties:
2623
dialect: org.hibernate.dialect.PostgreSQLDialect
2724
hibernate:
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
2+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-3.10.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.10.xsd">
3+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-1">
4+
<createTable tableName="automata">
5+
<column name="automaton_id" type="UUID">
6+
<constraints nullable="false" primaryKey="true" primaryKeyName="automataPK"/>
7+
</column>
8+
<column name="type" type="INT">
9+
<constraints nullable="false"/>
10+
</column>
11+
<column name="model" type="VARCHAR(255)">
12+
<constraints nullable="false"/>
13+
</column>
14+
<column name="set_group" type="VARCHAR(255)">
15+
<constraints nullable="false"/>
16+
</column>
17+
<column name="watched_element" type="VARCHAR(255)">
18+
<constraints nullable="false"/>
19+
</column>
20+
<column name="mapping_name" type="VARCHAR(255)"/>
21+
</createTable>
22+
</changeSet>
23+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-2">
24+
<createTable tableName="automaton_properties">
25+
<column name="automaton_id" type="UUID">
26+
<constraints nullable="false" primaryKey="true" primaryKeyName="automaton_propertiesPK"/>
27+
</column>
28+
<column name="name" type="VARCHAR(255)">
29+
<constraints nullable="false" primaryKey="true" primaryKeyName="automaton_propertiesPK"/>
30+
</column>
31+
<column name="type" type="INT"/>
32+
<column name="value" type="VARCHAR(255)"/>
33+
</createTable>
34+
</changeSet>
35+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-3">
36+
<createTable tableName="filters">
37+
<column name="filter_id" type="VARCHAR(255)">
38+
<constraints nullable="false" primaryKey="true" primaryKeyName="filtersPK"/>
39+
</column>
40+
<column name="rule_id" type="UUID">
41+
<constraints nullable="false" primaryKey="true" primaryKeyName="filtersPK"/>
42+
</column>
43+
<column name="operand" type="INT"/>
44+
<column name="property" type="VARCHAR(255)"/>
45+
<column name="type" type="INT"/>
46+
<column name="value" type="VARCHAR(255)"/>
47+
</createTable>
48+
</changeSet>
49+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-4">
50+
<createTable tableName="mappings">
51+
<column name="name" type="VARCHAR(255)">
52+
<constraints nullable="false" primaryKey="true" primaryKeyName="mappingsPK"/>
53+
</column>
54+
<column name="control_parameters" type="BOOLEAN">
55+
<constraints nullable="false"/>
56+
</column>
57+
</createTable>
58+
</changeSet>
59+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-5">
60+
<createTable tableName="model_parameter_definitions">
61+
<column name="model_name" type="VARCHAR(255)">
62+
<constraints nullable="false" primaryKey="true" primaryKeyName="model_parameter_definitionsPK"/>
63+
</column>
64+
<column name="name" type="VARCHAR(255)">
65+
<constraints nullable="false" primaryKey="true" primaryKeyName="model_parameter_definitionsPK"/>
66+
</column>
67+
<column name="fixed_value" type="VARCHAR(255)"/>
68+
<column name="origin" type="INT"/>
69+
<column name="origin_name" type="VARCHAR(255)"/>
70+
<column name="type" type="INT"/>
71+
</createTable>
72+
</changeSet>
73+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-6">
74+
<createTable tableName="model_parameter_sets">
75+
<column name="group_name" type="VARCHAR(255)">
76+
<constraints nullable="false" primaryKey="true" primaryKeyName="model_parameter_setsPK"/>
77+
</column>
78+
<column name="group_type" type="INT">
79+
<constraints nullable="false" primaryKey="true" primaryKeyName="model_parameter_setsPK"/>
80+
</column>
81+
<column name="model_name" type="VARCHAR(255)">
82+
<constraints nullable="false" primaryKey="true" primaryKeyName="model_parameter_setsPK"/>
83+
</column>
84+
<column name="name" type="VARCHAR(255)">
85+
<constraints nullable="false" primaryKey="true" primaryKeyName="model_parameter_setsPK"/>
86+
</column>
87+
<column name="last_modified_date" type="TIMESTAMP"/>
88+
</createTable>
89+
</changeSet>
90+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-7">
91+
<createTable tableName="model_parameters">
92+
<column name="group_name" type="VARCHAR(255)">
93+
<constraints nullable="false" primaryKey="true" primaryKeyName="model_parametersPK"/>
94+
</column>
95+
<column name="group_type" type="INT">
96+
<constraints nullable="false" primaryKey="true" primaryKeyName="model_parametersPK"/>
97+
</column>
98+
<column name="model_name" type="VARCHAR(255)">
99+
<constraints nullable="false" primaryKey="true" primaryKeyName="model_parametersPK"/>
100+
</column>
101+
<column name="name" type="VARCHAR(255)">
102+
<constraints nullable="false" primaryKey="true" primaryKeyName="model_parametersPK"/>
103+
</column>
104+
<column name="set_name" type="VARCHAR(255)">
105+
<constraints nullable="false" primaryKey="true" primaryKeyName="model_parametersPK"/>
106+
</column>
107+
<column name="value" type="VARCHAR(255)"/>
108+
</createTable>
109+
</changeSet>
110+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-8">
111+
<createTable tableName="model_sets_group">
112+
<column name="model_name" type="VARCHAR(255)">
113+
<constraints nullable="false" primaryKey="true" primaryKeyName="model_sets_groupPK"/>
114+
</column>
115+
<column name="name" type="VARCHAR(255)">
116+
<constraints nullable="false" primaryKey="true" primaryKeyName="model_sets_groupPK"/>
117+
</column>
118+
<column name="type" type="INT">
119+
<constraints nullable="false" primaryKey="true" primaryKeyName="model_sets_groupPK"/>
120+
</column>
121+
</createTable>
122+
</changeSet>
123+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-9">
124+
<createTable tableName="models">
125+
<column name="model_name" type="VARCHAR(255)">
126+
<constraints nullable="false" primaryKey="true" primaryKeyName="modelsPK"/>
127+
</column>
128+
<column name="equipment_type" type="INT"/>
129+
</createTable>
130+
</changeSet>
131+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-10">
132+
<createTable tableName="networks">
133+
<column name="network_id" type="UUID">
134+
<constraints nullable="false" primaryKey="true" primaryKeyName="networksPK"/>
135+
</column>
136+
<column name="network_name" type="VARCHAR(255)"/>
137+
</createTable>
138+
</changeSet>
139+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-11">
140+
<createTable tableName="rules">
141+
<column name="rule_id" type="UUID">
142+
<constraints nullable="false" primaryKey="true" primaryKeyName="rulesPK"/>
143+
</column>
144+
<column name="composition" type="VARCHAR(255)">
145+
<constraints nullable="false"/>
146+
</column>
147+
<column name="type" type="INT">
148+
<constraints nullable="false"/>
149+
</column>
150+
<column name="group_type" type="INT">
151+
<constraints nullable="false"/>
152+
</column>
153+
<column name="model" type="VARCHAR(255)">
154+
<constraints nullable="false"/>
155+
</column>
156+
<column name="set_group" type="VARCHAR(255)">
157+
<constraints nullable="false"/>
158+
</column>
159+
<column name="mapping_name" type="VARCHAR(255)"/>
160+
</createTable>
161+
</changeSet>
162+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-12">
163+
<createTable tableName="scripts">
164+
<column name="name" type="VARCHAR(255)">
165+
<constraints nullable="false" primaryKey="true" primaryKeyName="scriptsPK"/>
166+
</column>
167+
<column name="created_date" type="TIMESTAMP"/>
168+
<column name="parameters_file" type="CLOB"/>
169+
<column name="parent" type="VARCHAR(255)"/>
170+
<column name="script" type="CLOB">
171+
<constraints nullable="false"/>
172+
</column>
173+
</createTable>
174+
</changeSet>
175+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-13">
176+
<createIndex indexName="automaton_mappingName_index" tableName="automata">
177+
<column name="mapping_name"/>
178+
</createIndex>
179+
</changeSet>
180+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-14">
181+
<createIndex indexName="filter_rule_id_index" tableName="filters">
182+
<column name="rule_id"/>
183+
</createIndex>
184+
</changeSet>
185+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-15">
186+
<createIndex indexName="model_parameter_definitions_model_name_index" tableName="model_parameter_definitions">
187+
<column name="model_name"/>
188+
</createIndex>
189+
</changeSet>
190+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-16">
191+
<createIndex indexName="model_parameter_set_index" tableName="model_parameters">
192+
<column name="set_name"/>
193+
</createIndex>
194+
</changeSet>
195+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-17">
196+
<createIndex indexName="model_parameter_sets_group_name_index" tableName="model_parameter_sets">
197+
<column name="group_name"/>
198+
</createIndex>
199+
</changeSet>
200+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-18">
201+
<createIndex indexName="model_sets_group_model_name_index" tableName="model_sets_group">
202+
<column name="model_name"/>
203+
</createIndex>
204+
</changeSet>
205+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-19">
206+
<createIndex indexName="property_automaton_id_index" tableName="automaton_properties">
207+
<column name="automaton_id"/>
208+
</createIndex>
209+
</changeSet>
210+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-20">
211+
<createIndex indexName="rule_mappingName_index" tableName="rules">
212+
<column name="mapping_name"/>
213+
</createIndex>
214+
</changeSet>
215+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-21">
216+
<addForeignKeyConstraint baseColumnNames="automaton_id" baseTableName="automaton_properties" constraintName="automata_property_fk" deferrable="false" initiallyDeferred="false" referencedColumnNames="automaton_id" referencedTableName="automata" validate="true"/>
217+
</changeSet>
218+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-22">
219+
<addForeignKeyConstraint baseColumnNames="mapping_name" baseTableName="automata" constraintName="mapping_automata_fk" deferrable="false" initiallyDeferred="false" referencedColumnNames="name" referencedTableName="mappings" validate="true"/>
220+
</changeSet>
221+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-23">
222+
<addForeignKeyConstraint baseColumnNames="mapping_name" baseTableName="rules" constraintName="mapping_rules_fk" deferrable="false" initiallyDeferred="false" referencedColumnNames="name" referencedTableName="mappings" validate="true"/>
223+
</changeSet>
224+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-24">
225+
<addForeignKeyConstraint baseColumnNames="model_name" baseTableName="model_parameter_definitions" constraintName="model_parameter_definition_fk" deferrable="false" initiallyDeferred="false" referencedColumnNames="model_name" referencedTableName="models" validate="true"/>
226+
</changeSet>
227+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-25">
228+
<addForeignKeyConstraint baseColumnNames="model_name,group_name,group_type" baseTableName="model_parameter_sets" constraintName="model_parameter_sets_fk" deferrable="false" initiallyDeferred="false" referencedColumnNames="model_name,name,type" referencedTableName="model_sets_group" validate="true"/>
229+
</changeSet>
230+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-26">
231+
<addForeignKeyConstraint baseColumnNames="model_name" baseTableName="model_sets_group" constraintName="model_sets_groups_fk" deferrable="false" initiallyDeferred="false" referencedColumnNames="model_name" referencedTableName="models" validate="true"/>
232+
</changeSet>
233+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-27">
234+
<addForeignKeyConstraint baseColumnNames="group_name,group_type,model_name,set_name" baseTableName="model_parameters" constraintName="parameter_set_fk" deferrable="false" initiallyDeferred="false" referencedColumnNames="group_name,group_type,model_name,name" referencedTableName="model_parameter_sets" validate="true"/>
235+
</changeSet>
236+
<changeSet author="borsenbergerjac (generated)" id="1635328242976-28">
237+
<addForeignKeyConstraint baseColumnNames="rule_id" baseTableName="filters" constraintName="rules_filter_fk" deferrable="false" initiallyDeferred="false" referencedColumnNames="rule_id" referencedTableName="rules" validate="true"/>
238+
</changeSet>
239+
</databaseChangeLog>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
databaseChangeLog:
2+
3+
- include:
4+
file: changesets/changelog_2021-10-19T14:07:51Z.xml
5+
relativeToChangelogFile: true

src/test/resources/application-default.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
spring:
22
jpa:
33
database: H2
4-
hibernate:
5-
ddl-auto: create-drop
64
properties:
75
dialect: org.hibernate.dialect.H2Dialect
86
hibernate.format_sql: true

0 commit comments

Comments
 (0)