Skip to content

Commit

Permalink
Fix migrations to work with latest MariaDB patch versions
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed Aug 20, 2023
1 parent 0a2e75b commit 0205551
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 20 deletions.
38 changes: 20 additions & 18 deletions src/main/resources/db/migration/V0_7_7__update.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
ALTER TABLE `connector`
DROP FOREIGN KEY `FK_chargeBoxId_c`;
ALTER TABLE `reservation`
DROP FOREIGN KEY `FK_chargeBoxId_r`,
DROP FOREIGN KEY `FK_idTag_r`;

ALTER TABLE `chargebox`
CHANGE COLUMN `chargeBoxId` `chargeBoxId` VARCHAR(255) NOT NULL COMMENT '' ,
CHANGE COLUMN `endpoint_address` `endpoint_address` VARCHAR(255) NULL DEFAULT NULL COMMENT '' ,
Expand All @@ -14,9 +20,6 @@ CHANGE COLUMN `meterType` `meterType` VARCHAR(255) NULL DEFAULT NULL COMMENT ''
CHANGE COLUMN `meterSerialNumber` `meterSerialNumber` VARCHAR(255) NULL DEFAULT NULL COMMENT '' ,
CHANGE COLUMN `diagnosticsStatus` `diagnosticsStatus` VARCHAR(255) NULL DEFAULT NULL COMMENT '' ;


ALTER TABLE `connector`
DROP FOREIGN KEY `FK_chargeBoxId_c`;
ALTER TABLE `connector`
CHANGE COLUMN `chargeBoxId` `chargeBoxId` VARCHAR(255) NOT NULL COMMENT '' ;
ALTER TABLE `connector`
Expand All @@ -42,10 +45,6 @@ CHANGE COLUMN `errorCode` `errorCode` VARCHAR(255) NULL DEFAULT NULL COMMENT ''
CHANGE COLUMN `errorInfo` `errorInfo` VARCHAR(255) NULL DEFAULT NULL COMMENT '' ,
CHANGE COLUMN `vendorErrorCode` `vendorErrorCode` VARCHAR(255) NULL DEFAULT NULL COMMENT '' ;


ALTER TABLE `reservation`
DROP FOREIGN KEY `FK_chargeBoxId_r`,
DROP FOREIGN KEY `FK_idTag_r`;
ALTER TABLE `reservation`
CHANGE COLUMN `idTag` `idTag` VARCHAR(255) NOT NULL COMMENT '' ,
CHANGE COLUMN `chargeBoxId` `chargeBoxId` VARCHAR(255) NOT NULL COMMENT '' ,
Expand All @@ -54,11 +53,6 @@ ALTER TABLE `reservation`
ADD CONSTRAINT `FK_chargeBoxId_r`
FOREIGN KEY (`chargeBoxId`)
REFERENCES `chargebox` (`chargeBoxId`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
ADD CONSTRAINT `FK_idTag_r`
FOREIGN KEY (`idTag`)
REFERENCES `user` (`idTag`)
ON DELETE CASCADE
ON UPDATE NO ACTION;

Expand All @@ -68,12 +62,6 @@ ALTER TABLE `transaction`
CHANGE COLUMN `idTag` `idTag` VARCHAR(255) NOT NULL COMMENT '' ,
CHANGE COLUMN `startValue` `startValue` VARCHAR(255) NULL DEFAULT NULL COMMENT '' ,
CHANGE COLUMN `stopValue` `stopValue` VARCHAR(255) NULL DEFAULT NULL COMMENT '' ;
ALTER TABLE `transaction`
ADD CONSTRAINT `FK_idTag_t`
FOREIGN KEY (`idTag`)
REFERENCES `user` (`idTag`)
ON DELETE CASCADE
ON UPDATE NO ACTION;

ALTER TABLE `user`
DROP FOREIGN KEY `FK_user_parentIdTag`;
Expand All @@ -86,3 +74,17 @@ FOREIGN KEY (`parentIdTag`)
REFERENCES `user` (`idTag`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;

ALTER TABLE `transaction`
ADD CONSTRAINT `FK_idTag_t`
FOREIGN KEY (`idTag`)
REFERENCES `user` (`idTag`)
ON DELETE CASCADE
ON UPDATE NO ACTION;

ALTER TABLE `reservation`
ADD CONSTRAINT `FK_idTag_r`
FOREIGN KEY (`idTag`)
REFERENCES `user` (`idTag`)
ON DELETE CASCADE
ON UPDATE NO ACTION;
101 changes: 99 additions & 2 deletions src/main/resources/db/migration/V0_8_6__update.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,49 @@ LOCK TABLES
ocpp_tag WRITE,
reservation WRITE,
settings WRITE,
schema_version WRITE,
`transaction` WRITE,
`user` WRITE;

SET FOREIGN_KEY_CHECKS = 0;
# alter table charge_box
# drop foreign key FK_charge_box_address_apk;

# alter table connector
# drop foreign key FK_connector_charge_box_cbid;

alter table connector_meter_value
drop foreign key FK_pk_cm;

alter table connector_meter_value
drop foreign key FK_tid_cm;

alter table connector_status
drop foreign key FK_cs_pk;

alter table ocpp_tag
drop foreign key FK_ocpp_tag_parent_id_tag;

alter table reservation
drop foreign key FK_reservation_charge_box_cbid;

alter table reservation
drop foreign key FK_reservation_ocpp_tag_id_tag;

alter table reservation
drop foreign key FK_transaction_pk_r;

alter table transaction
drop foreign key FK_connector_pk_t;

alter table transaction
drop foreign key FK_transaction_ocpp_tag_id_tag;

alter table user
drop foreign key FK_user_address_apk;

alter table user
drop foreign key FK_user_ocpp_tag_otpk;


ALTER TABLE charge_box CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE address CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Expand All @@ -34,7 +73,65 @@ ALTER TABLE settings CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE `transaction` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE `user` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

SET FOREIGN_KEY_CHECKS = 1;
alter table charge_box
add constraint FK_charge_box_address_apk
foreign key (address_pk) references stevedb.address (address_pk)
on delete set null;

alter table connector
add constraint FK_connector_charge_box_cbid
foreign key (charge_box_id) references stevedb.charge_box (charge_box_id)
on delete cascade;

alter table stevedb.connector_meter_value
add constraint FK_pk_cm
foreign key (connector_pk) references stevedb.connector (connector_pk)
on delete cascade;

alter table stevedb.connector_meter_value
add constraint FK_tid_cm
foreign key (transaction_pk) references stevedb.transaction (transaction_pk)
on delete set null;

alter table stevedb.connector_status
add constraint FK_cs_pk
foreign key (connector_pk) references stevedb.connector (connector_pk)
on delete cascade;
alter table stevedb.ocpp_tag
add constraint FK_ocpp_tag_parent_id_tag
foreign key (parent_id_tag) references stevedb.ocpp_tag (id_tag);
alter table stevedb.reservation
add constraint FK_reservation_charge_box_cbid
foreign key (charge_box_id) references stevedb.charge_box (charge_box_id)
on delete cascade;

alter table stevedb.reservation
add constraint FK_reservation_ocpp_tag_id_tag
foreign key (id_tag) references stevedb.ocpp_tag (id_tag)
on delete cascade;

alter table stevedb.reservation
add constraint FK_transaction_pk_r
foreign key (transaction_pk) references stevedb.transaction (transaction_pk);

alter table stevedb.transaction
add constraint FK_connector_pk_t
foreign key (connector_pk) references stevedb.connector (connector_pk)
on delete cascade;

alter table stevedb.transaction
add constraint FK_transaction_ocpp_tag_id_tag
foreign key (id_tag) references stevedb.ocpp_tag (id_tag)
on delete cascade;
alter table stevedb.user
add constraint FK_user_address_apk
foreign key (address_pk) references stevedb.address (address_pk)
on delete set null;

alter table stevedb.user
add constraint FK_user_ocpp_tag_otpk
foreign key (ocpp_tag_pk) references stevedb.ocpp_tag (ocpp_tag_pk)
on delete set null;

UNLOCK TABLES;

Expand Down

0 comments on commit 0205551

Please sign in to comment.