From f29c070a2a0e1a5e551a5350573605978076854f Mon Sep 17 00:00:00 2001 From: Rehili Ghazwa Date: Thu, 21 Nov 2024 13:12:38 +0100 Subject: [PATCH] fix script --- .../changesets/changelog_20241118T203926Z.xml | 20 ++--- ...eCapabilityCurvePoint_20242011T150009Z.sql | 84 ++++++++++--------- ...pabilityCurvePoint_pg_20242011T150009Z.sql | 61 ++++++++++++++ 3 files changed, 115 insertions(+), 50 deletions(-) create mode 100644 src/main/resources/db/changelog/changesets/migrationReactiveCapabilityCurvePoint_pg_20242011T150009Z.sql diff --git a/src/main/resources/db/changelog/changesets/changelog_20241118T203926Z.xml b/src/main/resources/db/changelog/changesets/changelog_20241118T203926Z.xml index ac18d3f65..7562edfa8 100644 --- a/src/main/resources/db/changelog/changesets/changelog_20241118T203926Z.xml +++ b/src/main/resources/db/changelog/changesets/changelog_20241118T203926Z.xml @@ -17,18 +17,18 @@ - - - - - - - - - + splitStatements="true" + stripComments="true"/> + diff --git a/src/main/resources/db/changelog/changesets/migrationReactiveCapabilityCurvePoint_20242011T150009Z.sql b/src/main/resources/db/changelog/changesets/migrationReactiveCapabilityCurvePoint_20242011T150009Z.sql index 6317a6bab..92dc6a1c3 100644 --- a/src/main/resources/db/changelog/changesets/migrationReactiveCapabilityCurvePoint_20242011T150009Z.sql +++ b/src/main/resources/db/changelog/changesets/migrationReactiveCapabilityCurvePoint_20242011T150009Z.sql @@ -1,57 +1,61 @@ +alter table generator_modification_entity_reactive_capability_curve_points add column id UUID default random_uuid(); +alter table battery_modification_entity_reactive_capability_curve_points add column id UUID default random_uuid(); +alter table converter_station_modification_rcc_points add column id UUID default random_uuid(); + with position_value_generator as ( select + id, generator_modification_entity_id, - old_maxq, - old_minq, - oldp, - maxq, - minq, - p, - (row_number() over (partition by generator_modification_entity_id) - 1) AS pos_point_new - FROM generator_modification_entity_reactive_capability_curve_points + (row_number() over (partition by generator_modification_entity_id) - 1) as pos_point_new + from generator_modification_entity_reactive_capability_curve_points ) - -update generator_modification_entity_reactive_capability_curve_points g -set pos_point = c.pos_point_new -from position_value_generator c -where g.generator_modification_entity_id = c.generator_modification_entity_id - and g.old_maxq = c.old_maxq and g.old_minq = c.old_minq and g.oldp = c.oldp - and g.maxq = c.maxq and g.minq = c.minq and g.p = c.p; +update generator_modification_entity_reactive_capability_curve_points +set pos_point = ( + select pos_point_new + from position_value_generator + where position_value_generator.id = generator_modification_entity_reactive_capability_curve_points.id +) +where id in ( + select id + from position_value_generator +); with position_value_battery as ( select + id, battery_modification_entity_id, - old_maxq, - old_minq, - oldp, - maxq, - minq, - p, - (row_number() OVER (partition by battery_modification_entity_id) - 1) AS pos_point_new + (row_number() over (partition by battery_modification_entity_id) - 1) as pos_point_new from battery_modification_entity_reactive_capability_curve_points ) -update battery_modification_entity_reactive_capability_curve_points g -set pos_point = c.pos_point_new -from position_value_battery c -where g.battery_modification_entity_id = c.battery_modification_entity_id - and g.old_maxq = c.old_maxq and g.old_minq = c.old_minq and g.oldp = c.oldp - and g.maxq = c.maxq and g.minq = c.minq and g.p = c.p; +update battery_modification_entity_reactive_capability_curve_points +set pos_point = ( + select pos_point_new + from position_value_battery + where position_value_battery.id = battery_modification_entity_reactive_capability_curve_points.id +) +where id in ( + select id + from position_value_battery +); with position_value_converter_station as ( select + id, converter_station_modification_entity_id, - old_maxq, - old_minq, - oldp, - maxq, - minq, - p, (row_number() over (partition by converter_station_modification_entity_id) - 1) as pos_point_new from converter_station_modification_rcc_points ) -update converter_station_modification_rcc_points g -set pos_point = c.pos_point_new -from position_value_converter_station c -where g.converter_station_modification_entity_id = c.converter_station_modification_entity_id - and g.old_maxq = c.old_maxq and g.old_minq = c.old_minq and g.oldp = c.oldp - and g.maxq = c.maxq and g.minq = c.minq and g.p = c.p; +update converter_station_modification_rcc_points +set pos_point = ( + select pos_point_new + from position_value_converter_station + where position_value_converter_station.id = converter_station_modification_rcc_points.id +) +where id in ( + select id + from position_value_converter_station +); + +alter table generator_modification_entity_reactive_capability_curve_points drop column id; +alter table battery_modification_entity_reactive_capability_curve_points drop column id; +alter table converter_station_modification_rcc_points drop column id; \ No newline at end of file diff --git a/src/main/resources/db/changelog/changesets/migrationReactiveCapabilityCurvePoint_pg_20242011T150009Z.sql b/src/main/resources/db/changelog/changesets/migrationReactiveCapabilityCurvePoint_pg_20242011T150009Z.sql new file mode 100644 index 000000000..4fc0af3c0 --- /dev/null +++ b/src/main/resources/db/changelog/changesets/migrationReactiveCapabilityCurvePoint_pg_20242011T150009Z.sql @@ -0,0 +1,61 @@ +alter table generator_modification_entity_reactive_capability_curve_points add column id UUID default gen_random_uuid(); +alter table battery_modification_entity_reactive_capability_curve_points add column id UUID default gen_random_uuid(); +alter table converter_station_modification_rcc_points add column id UUID default gen_random_uuid(); + +with position_value_generator as ( + select + id, + generator_modification_entity_id, + (row_number() over (partition by generator_modification_entity_id) - 1) AS pos_point_new + from generator_modification_entity_reactive_capability_curve_points +) +update generator_modification_entity_reactive_capability_curve_points +set pos_point = ( + select pos_point_new + from position_value_generator + where position_value_generator.id = generator_modification_entity_reactive_capability_curve_points.id +) +where id in ( + select id + from position_value_generator +); + +with position_value_battery as ( + select + id, + battery_modification_entity_id, + (row_number() over (partition by battery_modification_entity_id) - 1) AS pos_point_new + from battery_modification_entity_reactive_capability_curve_points +) +update battery_modification_entity_reactive_capability_curve_points +set pos_point = ( + select pos_point_new + from position_value_battery + where position_value_battery.id = battery_modification_entity_reactive_capability_curve_points.id +) +where id in ( + select id + from position_value_battery +); + +with position_value_converter_station as ( + select + id, + converter_station_modification_entity_id, + (row_number() over (partition by converter_station_modification_entity_id) - 1) AS pos_point_new + from converter_station_modification_rcc_points +) +update converter_station_modification_rcc_points +set pos_point = ( + select pos_point_new + from position_value_converter_station + where position_value_converter_station.id = converter_station_modification_rcc_points.id +) +where id in ( + select id + from position_value_converter_station +); + +alter table generator_modification_entity_reactive_capability_curve_points drop column id; +alter table battery_modification_entity_reactive_capability_curve_points drop column id; +alter table converter_station_modification_rcc_points drop column id; \ No newline at end of file