Skip to content

Commit

Permalink
Add data migration
Browse files Browse the repository at this point in the history
Signed-off-by: BOUHOURS Antoine <[email protected]>
  • Loading branch information
antoinebhs committed Mar 28, 2024
1 parent 54dcd00 commit 2f3b052
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
<changeSet author="abouhours" id="2986331049275-1">
<changeSet author="bouhoursant" id="2986331049277-1">
<createTable tableName="extension">
<column name="equipmentid" type="VARCHAR(255)">
<constraints nullable="false"/>
Expand All @@ -19,29 +19,18 @@
</column>
<column name="value_" type="TEXT"/>
</createTable>
</changeSet>
<changeSet author="abouhours" id="2986331049275-2">
<createIndex indexName="extension_networkuuid_variantnum_equipmenttype_idx" tableName="extension">
<column name="networkuuid"/>
<column name="variantnum"/>
<column name="equipmenttype"/>
</createIndex>
</changeSet>
<changeSet author="abouhours" id="2986331049275-3">
<addPrimaryKey columnNames="networkuuid, variantnum, equipmentid, name" constraintName="extension_pkey" tableName="extension"/>
</changeSet>
<changeSet author="abouhours" id="2986331049275-4">
<!-- TODO finish migrations, it should not be necessary to add the @class with jsonb, it's for testing... -->
<!-- <sql>-->
<!-- INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name, value_)-->
<!-- SELECT networkuuid, variantnum, id, 'BATTERY', 'activePowerControl',-->
<!-- jsonb_set(-->
<!-- COALESCE(activepowercontrol::jsonb, '{}'::jsonb),-->
<!-- '{@class}',-->
<!-- '"com.powsybl.network.store.model.ActivePowerControlAttributes"'::jsonb-->
<!-- )-->
<!-- FROM battery-->
<!-- WHERE activepowercontrol::jsonb IS NOT NULL-->
<!-- </sql>-->
<changeSet author="bouhoursant" id="2986331049277-2">
<sqlFile
path="migrationExtensions_20240306T120000Z.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true"/>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name, value_)
SELECT networkuuid, variantnum, id, 'BATTERY', 'activePowerControl',
jsonb_set(
COALESCE(activepowercontrol::jsonb, '{}'::jsonb),
'{@type}',
'"activePowerControl"'::jsonb
)
FROM battery
WHERE activepowercontrol IS NOT NULL;

INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name, value_)
SELECT networkuuid, variantnum, id, 'GENERATOR', 'activePowerControl',
jsonb_set(
COALESCE(activepowercontrol::jsonb, '{}'::jsonb),
'{@type}',
'"activePowerControl"'::jsonb
)
FROM generator
WHERE activepowercontrol IS NOT NULL;

INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name, value_)
SELECT networkuuid, variantnum, id, 'GENERATOR', 'startup',
jsonb_set(
COALESCE(generatorstartup::jsonb, '{}'::jsonb),
'{@type}',
'"startup"'::jsonb
)
FROM generator
WHERE generatorstartup IS NOT NULL;

INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name, value_)
SELECT networkuuid, variantnum, id, 'LINE', 'operatingStatus',
jsonb_build_object(
'@type', 'operatingStatus',
'operatingStatus', operatingStatus::text
)
FROM line
WHERE operatingStatus IS NOT NULL;

INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name, value_)
SELECT networkuuid, variantnum, id, 'HVDC_LINE', 'operatingStatus',
jsonb_build_object(
'@type', 'operatingStatus',
'operatingStatus', operatingStatus::text
)
FROM hvdcline
WHERE operatingStatus IS NOT NULL;

INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name, value_)
SELECT networkuuid, variantnum, id, 'TIE_LINE', 'operatingStatus',
jsonb_build_object(
'@type', 'operatingStatus',
'operatingStatus', operatingStatus::text
)
FROM tieline
WHERE operatingStatus IS NOT NULL;

INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name, value_)
SELECT networkuuid, variantnum, id, 'DANGLING_LINE', 'operatingStatus',
jsonb_build_object(
'@type', 'operatingStatus',
'operatingStatus', operatingStatus::text
)
FROM danglingline
WHERE operatingStatus IS NOT NULL;

INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name, value_)
SELECT networkuuid, variantnum, id, 'TWO_WINDINGS_TRANSFORMER', 'operatingStatus',
jsonb_build_object(
'@type', 'operatingStatus',
'operatingStatus', operatingStatus::text
)
FROM twowindingstransformer
WHERE operatingStatus IS NOT NULL;

INSERT INTO extension (networkuuid, variantnum, equipmentid, equipmentType, name, value_)
SELECT networkuuid, variantnum, id, 'THREE_WINDINGS_TRANSFORMER', 'operatingStatus',
jsonb_build_object(
'@type', 'operatingStatus',
'operatingStatus', operatingStatus::text
)
FROM threewindingstransformer
WHERE operatingStatus IS NOT NULL;

0 comments on commit 2f3b052

Please sign in to comment.