-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
device management 1: Add 'is pinned on-release' column and synchroniz…
…e values from 'should be running release' Change-type: minor
- Loading branch information
Andrea Rosci
authored and
Andrea Rosci
committed
Jun 5, 2024
1 parent
c51ccdf
commit a8ed7d1
Showing
5 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-- Add the column if it does not exist | ||
ALTER TABLE "device" | ||
ADD COLUMN IF NOT EXISTS "is pinned on-release" INTEGER NULL; | ||
|
||
-- Add an index for optimization if it does not exist | ||
CREATE INDEX IF NOT EXISTS "device_is_pinned_on_release_application_idx" | ||
ON "device" ("is pinned on-release", "belongs to-application"); | ||
|
||
-- Check and add the foreign key constraint conditionally | ||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS ( | ||
SELECT 1 | ||
FROM information_schema.table_constraints AS tc | ||
JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name | ||
WHERE tc.constraint_type = 'FOREIGN KEY' | ||
AND tc.table_schema = CURRENT_SCHEMA() | ||
AND tc.table_name = 'device' | ||
AND kcu.column_name = 'is pinned on-release' | ||
) THEN | ||
ALTER TABLE "device" | ||
ADD CONSTRAINT "device_is pinned on-release_fkey" FOREIGN KEY ("is pinned on-release") REFERENCES "release" ("id"); | ||
END IF; | ||
END; | ||
$$; |