Skip to content

Commit

Permalink
fix script
Browse files Browse the repository at this point in the history
  • Loading branch information
ghazwarhili committed Nov 21, 2024
1 parent 0950432 commit f29c070
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
</changeSet>
<changeSet author="rehiligha" id="1731962383078-34">
<sqlFile
dbms="!postgresql"
encoding="UTF-8"
path="migrationReactiveCapabilityCurvePoint_20242011T150009Z.sql"
relativeToChangelogFile="true"
splitStatements="true"/>
</changeSet>
<changeSet author="rehiligha (generated)" id="1731962383078-35">
<addPrimaryKey columnNames="battery_modification_entity_id, pos_point" constraintName="battery_modification_entity_reactive_capability_curve_pointsPK" tableName="battery_modification_entity_reactive_capability_curve_points"/>
</changeSet>
<changeSet author="rehiligha (generated)" id="1731962383078-36">
<addPrimaryKey columnNames="converter_station_modification_entity_id, pos_point" constraintName="converter_station_modification_rcc_pointsPK" tableName="converter_station_modification_rcc_points"/>
</changeSet>
<changeSet author="rehiligha (generated)" id="1731962383078-37">
<addPrimaryKey columnNames="generator_modification_entity_id, pos_point" constraintName="generator_modification_entity_reactive_capability_c_4905C1D9_PK" tableName="generator_modification_entity_reactive_capability_curve_points"/>
splitStatements="true"
stripComments="true"/>
<sqlFile
dbms="postgresql"
encoding="UTF-8"
path="migrationReactiveCapabilityCurvePoint_pg_20242011T150009Z.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true"/>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit f29c070

Please sign in to comment.