Skip to content

Commit 5042236

Browse files
Fix install script for fk_device_profile_ota_package constraint to work on repeated install
1 parent 19a9534 commit 5042236

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

dao/src/main/resources/sql/schema-entities.sql

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,17 @@ CREATE TABLE IF NOT EXISTS device_profile (
242242
CONSTRAINT fk_software_device_profile FOREIGN KEY (software_id) REFERENCES ota_package(id)
243243
);
244244

245-
ALTER TABLE ota_package
246-
ADD CONSTRAINT fk_device_profile_ota_package
247-
FOREIGN KEY (device_profile_id) REFERENCES device_profile (id)
248-
ON DELETE CASCADE;
245+
DO
246+
$$
247+
BEGIN
248+
IF NOT EXISTS(SELECT 1 FROM pg_constraint WHERE conname = 'fk_device_profile_ota_package') THEN
249+
ALTER TABLE ota_package
250+
ADD CONSTRAINT fk_device_profile_ota_package
251+
FOREIGN KEY (device_profile_id) REFERENCES device_profile (id)
252+
ON DELETE CASCADE;
253+
END IF;
254+
END;
255+
$$;
249256

250257
-- We will use one-to-many relation in the first release and extend this feature in case of user requests
251258
-- CREATE TABLE IF NOT EXISTS device_profile_firmware (

0 commit comments

Comments
 (0)