Skip to content

Migration script

  • MSSQL
  • Wind power
  • v3 to v4
-- Note 20240918 Martijn: In an earlier version of the v2-to-v3.sql we forgot to remove
-- a few constrains. Therefore are already added here. The constrains will only be removed
-- if they exist. Therefore destinations that started at v3 can execute this SQL and will
-- not be impacted.
DECLARE @Constraint8 nvarchar(200)
SELECT @Constraint8 = Name FROM SYS.DEFAULT_CONSTRAINTS
WHERE PARENT_OBJECT_ID = OBJECT_ID('dbo.teleport_wind_power')
AND PARENT_COLUMN_ID = (SELECT column_id FROM sys.columns
WHERE NAME = N'wind_speed'
AND object_id = OBJECT_ID(N'dbo.teleport_wind_power'))
IF @Constraint8 IS NOT NULL
EXEC('ALTER TABLE dbo.teleport_wind_power DROP CONSTRAINT ' + @Constraint8);
DECLARE @Constraint9 nvarchar(200)
SELECT @Constraint9 = Name FROM SYS.DEFAULT_CONSTRAINTS
WHERE PARENT_OBJECT_ID = OBJECT_ID('dbo.teleport_wind_power')
AND PARENT_COLUMN_ID = (SELECT column_id FROM sys.columns
WHERE NAME = N'active_power_limit_percentage'
AND object_id = OBJECT_ID(N'dbo.teleport_wind_power'))
IF @Constraint9 IS NOT NULL
EXEC('ALTER TABLE dbo.teleport_wind_power DROP CONSTRAINT ' + @Constraint9);
DECLARE @Constraint10 nvarchar(200)
SELECT @Constraint10 = Name FROM SYS.DEFAULT_CONSTRAINTS
WHERE PARENT_OBJECT_ID = OBJECT_ID('dbo.teleport_wind_power_converters')
AND PARENT_COLUMN_ID = (SELECT column_id FROM sys.columns
WHERE NAME = N'wind_speed'
AND object_id = OBJECT_ID(N'dbo.teleport_wind_power_converters'))
IF @Constraint10 IS NOT NULL
EXEC('ALTER TABLE dbo.teleport_wind_power_converters DROP CONSTRAINT ' + @Constraint10);
-- ADD OTHER MIGRATIONS BELOW HERE
IF EXISTS (SELECT NULL FROM SYS.EXTENDED_PROPERTIES WHERE [major_id] = OBJECT_ID('teleport_wind_power') AND [name] = N'version' AND [minor_id] = 0)
EXEC sys.sp_updateextendedproperty
@name=N'version',
@value=4,
@level0type=N'SCHEMA',
@level0name=N'dbo',
@level1type=N'TABLE',
@level1name=N'teleport_wind_power'
ELSE
EXEC sys.sp_addextendedproperty
@name=N'version',
@value=4,
@level0type=N'SCHEMA',
@level0name=N'dbo',
@level1type=N'TABLE',
@level1name=N'teleport_wind_power';
ALTER TABLE teleport_wind_power
ADD
reactive_power decimal(23,3) DEFAULT NULL,
power_factor decimal(5, 4) DEFAULT NULL,
setpoints_confirmed_active_power_limit_percentage decimal(4,1) DEFAULT NULL,
setpoints_confirmed_active_power_limit decimal(23, 3) DEFAULT NULL,
setpoints_confirmed_reactive_power_reactive_power decimal(23,3) DEFAULT NULL,
setpoints_confirmed_reactive_power_power_factor decimal(5, 4) DEFAULT NULL,
setpoints_confirmed_reactive_power_mode varchar(32) DEFAULT NULL, setpoints_desired_active_power_limit_cloud decimal(23, 3) DEFAULT NULL,
setpoints_desired_active_power_limit_active_control decimal(23, 3) DEFAULT NULL,
setpoints_desired_active_power_limit_grid_operator decimal(23, 3) DEFAULT NULL,
setpoints_desired_active_power_limit_modbus_server decimal(23, 3) DEFAULT NULL,
setpoints_desired_active_power_limit_afrr_delta decimal(23, 3) DEFAULT NULL,
setpoints_desired_active_power_limit_afrr_reference decimal(23, 3) DEFAULT NULL,
setpoints_desired_reactive_power_cloud_reactive_power decimal(23,3) DEFAULT NULL,
setpoints_desired_reactive_power_cloud_power_factor decimal(5, 4) DEFAULT NULL,
setpoints_desired_reactive_power_cloud_mode varchar(32) DEFAULT NULL,
setpoints_desired_reactive_power_grid_operator_reactive_power decimal(23,3) DEFAULT NULL,
setpoints_desired_reactive_power_grid_operator_power_factor decimal(5, 4) DEFAULT NULL,
setpoints_desired_reactive_power_grid_operator_mode varchar(32) DEFAULT NULL,
setpoints_effective_active_power_limit decimal(23, 3) DEFAULT NULL,
setpoints_effective_reactive_power_reactive_power decimal(23,3) DEFAULT NULL,
setpoints_effective_reactive_power_power_factor decimal(5, 4) DEFAULT NULL,
setpoints_effective_reactive_power_mode varchar(32) DEFAULT NULL;
-- The `active_power_limit_percentage` field is deprecated and replaced by `setpoints_confirmed_active_power_limit_percentage`.
-- Existing values are migrated accordingly to ensure a consistent representation of active power limits in percentage form.
-- This change improves standardization and flexibility in power control settings.
UPDATE teleport_wind_power
SET setpoints_confirmed_active_power_limit_percentage = active_power_limit_percentage;
DECLARE @ConstraintName11 NVARCHAR(200)
SELECT @ConstraintName11 = Name FROM SYS.DEFAULT_CONSTRAINTS
WHERE PARENT_OBJECT_ID = OBJECT_ID('dbo.teleport_wind_power')
AND PARENT_COLUMN_ID = (SELECT column_id FROM sys.columns
WHERE NAME = N'active_power_limit_percentage'
AND object_id = OBJECT_ID(N'dbo.teleport_wind_power'));
IF @ConstraintName11 IS NOT NULL
EXEC('ALTER TABLE teleport_wind_power DROP CONSTRAINT ' + @ConstraintName11);
ALTER TABLE teleport_wind_power
DROP COLUMN active_power_limit_percentage;
ALTER TABLE teleport_wind_power_converters
ADD
reactive_power decimal(23,3) DEFAULT NULL,
power_factor decimal(5, 4) DEFAULT NULL;