fix: make migration 006 idempotent for UNIQUE constraint
Some checks failed
CI Pipeline / Rust Format Check (push) Failing after 6s
CI Pipeline / Clippy Lints (push) Successful in 1m13s
CI Pipeline / Rust Unit Tests (push) Successful in 1m17s
CI Pipeline / Security Audit (push) Successful in 32s
CI Pipeline / Frontend Lint & Type Check (push) Successful in 59s
CI Pipeline / Build .deb & Release (push) Has been skipped
Some checks failed
CI Pipeline / Rust Format Check (push) Failing after 6s
CI Pipeline / Clippy Lints (push) Successful in 1m13s
CI Pipeline / Rust Unit Tests (push) Successful in 1m17s
CI Pipeline / Security Audit (push) Successful in 32s
CI Pipeline / Frontend Lint & Type Check (push) Successful in 59s
CI Pipeline / Build .deb & Release (push) Has been skipped
This commit is contained in:
@ -7,6 +7,13 @@ USING host_patch_data b
|
||||
WHERE a.host_id = b.host_id
|
||||
AND a.polled_at < b.polled_at;
|
||||
|
||||
-- Step 2: Add UNIQUE constraint on host_id
|
||||
ALTER TABLE host_patch_data
|
||||
ADD CONSTRAINT host_patch_data_host_id_key UNIQUE (host_id);
|
||||
-- Step 2: Add UNIQUE constraint on host_id (idempotent)
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint WHERE conname = 'host_patch_data_host_id_key'
|
||||
) THEN
|
||||
ALTER TABLE host_patch_data
|
||||
ADD CONSTRAINT host_patch_data_host_id_key UNIQUE (host_id);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
Reference in New Issue
Block a user