Skip to content

Migration script

  • MySQL
  • Meter power
  • v1 to v2
ALTER TABLE teleport_meter_power
ADD COLUMN voltage_phase_l1 decimal(23,3) DEFAULT NULL AFTER attempt,
ADD COLUMN voltage_phase_l2 decimal(23,3) DEFAULT NULL AFTER voltage_phase_l1,
ADD COLUMN voltage_phase_l3 decimal(23,3) DEFAULT NULL AFTER voltage_phase_l2,
ADD COLUMN voltage_line_l1 decimal(23,3) DEFAULT NULL AFTER voltage_phase_l3,
ADD COLUMN voltage_line_l2 decimal(23,3) DEFAULT NULL AFTER voltage_line_l1,
ADD COLUMN voltage_line_l3 decimal(23,3) DEFAULT NULL AFTER voltage_line_l2,
ADD COLUMN current_phase_l1 decimal(23,3) DEFAULT NULL AFTER voltage_line_l3,
ADD COLUMN current_phase_l2 decimal(23,3) DEFAULT NULL AFTER current_phase_l1,
ADD COLUMN current_phase_l3 decimal(23,3) DEFAULT NULL AFTER current_phase_l2,
ADD COLUMN current_line_l1 decimal(23,3) DEFAULT NULL AFTER current_phase_l3,
ADD COLUMN current_line_l2 decimal(23,3) DEFAULT NULL AFTER current_line_l1,
ADD COLUMN current_line_l3 decimal(23,3) DEFAULT NULL AFTER current_line_l2,
ADD COLUMN three_phase_connection_type varchar(32) DEFAULT NULL AFTER current_line_l3,
ADD COLUMN apparent_power_l1 decimal(23,3) DEFAULT NULL AFTER reactive_power_sum,
ADD COLUMN apparent_power_l2 decimal(23,3) DEFAULT NULL AFTER apparent_power_l1,
ADD COLUMN apparent_power_l3 decimal(23,3) DEFAULT NULL AFTER apparent_power_l2,
ADD COLUMN apparent_power_sum decimal(23,3) DEFAULT NULL AFTER apparent_power_l3,
ADD COLUMN power_factor_l1 decimal(5, 4) DEFAULT NULL AFTER apparent_power_sum,
ADD COLUMN power_factor_l2 decimal(5, 4) DEFAULT NULL AFTER power_factor_l1,
ADD COLUMN power_factor_l3 decimal(5, 4) DEFAULT NULL AFTER power_factor_l2;
-- The phase voltage values are mapped to corresponding phase voltage fields:
-- `voltage_phase_l1 = phase_voltage_l1`, `voltage_phase_l2 = phase_voltage_l2`, `voltage_phase_l3 = phase_voltage_l3`.
-- The line voltage fields are set to NULL, based on the assumption that all connection types are wye-connected, where phase and line voltages are not equal.
-- Current values are mapped to both phase and line fields, as in wye-connected metering, phase and line currents are equal:
-- `current_phase_l1 = current_l1`, `current_phase_l2 = current_l2`, `current_phase_l3 = current_l3`.
-- `current_line_l1 = current_l1`, `current_line_l2 = current_l2`, `current_line_l3 = current_l3`.
UPDATE teleport_meter_power
SET
voltage_phase_l1 = phase_voltage_l1,
voltage_phase_l2 = phase_voltage_l2,
voltage_phase_l3 = phase_voltage_l3,
current_phase_l1 = current_l1,
current_phase_l2 = current_l2,
current_phase_l3 = current_l3,
current_line_l1 = current_l1,
current_line_l2 = current_l2,
current_line_l3 = current_l3;
ALTER TABLE teleport_meter_power
DROP COLUMN phase_voltage_l1,
DROP COLUMN phase_voltage_l2,
DROP COLUMN phase_voltage_l3,
DROP COLUMN current_l1,
DROP COLUMN current_l2,
DROP COLUMN current_l3;
ALTER TABLE teleport_meter_power COMMENT = '{"version":2}';