mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-10-23 07:42:05 +00:00
fix: migration to properly drop unique index on friendly_name
The migration was dropping the constraint but not the underlying unique index. In PostgreSQL, unique constraints and unique indexes can exist independently. This caused auto-enrollment to fail with 'unique constraint violated' errors. Added explicit DROP INDEX statement to ensure the unique index is removed, allowing duplicate friendly_name values while machine_id remains unique.
This commit is contained in:
@@ -7,6 +7,9 @@ UPDATE "hosts" SET "machine_id" = 'migrated-' || "api_id" WHERE "machine_id" IS
|
||||
-- Remove the unique constraint from friendly_name
|
||||
ALTER TABLE "hosts" DROP CONSTRAINT IF EXISTS "hosts_friendly_name_key";
|
||||
|
||||
-- Also drop the unique index if it exists (constraint and index can exist separately)
|
||||
DROP INDEX IF EXISTS "hosts_friendly_name_key";
|
||||
|
||||
-- Now make machine_id NOT NULL and add unique constraint
|
||||
ALTER TABLE "hosts" ALTER COLUMN "machine_id" SET NOT NULL;
|
||||
ALTER TABLE "hosts" ADD CONSTRAINT "hosts_machine_id_key" UNIQUE ("machine_id");
|
||||
|
Reference in New Issue
Block a user