-
-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: replace datalayer ids with uuids #1630
Conversation
ca38c77
to
ed40d5a
Compare
I've successfully migrated my local database with UUIDs, with the updated branch here. (edit: ruff formated everything) |
), | ||
migrations.RunPython(gen_uuid, reverse_code=migrations.RunPython.noop), | ||
migrations.RunSQL( | ||
"ALTER TABLE umap_datalayer DROP CONSTRAINT umap_datalayer_pkey" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this will work on other systems, as the constraints seems to be named uniquely on different installs.
This can be helpful in situations where the name of the index is not known, as it can be with pre 1.0 deployed instance. This commit also generates the UUIDs directly using an SQL statement.
9ca5800
to
176d03d
Compare
176d03d
to
9648c8b
Compare
7682d68
to
f82897f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Here is the generated SQL when running the migrations ALTER TABLE "umap_datalayer" ALTER COLUMN "uuid" DROP DEFAULT
UPDATE umap_datalayer SET uuid = gen_random_uuid()
DO $$
BEGIN
EXECUTE 'ALTER TABLE umap_datalayer DROP CONSTRAINT ' || (
SELECT indexname
FROM pg_indexes
WHERE tablename = 'umap_datalayer' AND indexname LIKE '%pk%'
);
END $$;
ALTER TABLE "umap_datalayer" ALTER COLUMN "id" DROP IDENTITY IF EXISTS
ALTER TABLE "umap_datalayer" ALTER COLUMN "id" TYPE integer, ALTER COLUMN "id" DROP NOT NULL
DROP INDEX IF EXISTS "umap_datalayer_id_5f429f28_like"
ALTER TABLE "umap_datalayer" RENAME COLUMN "id" TO "old_id"
ALTER TABLE "umap_datalayer" ALTER COLUMN "uuid" SET DEFAULT '135add95-f480-4467-9eba-84c7e1827785'::uuid
UPDATE "umap_datalayer" SET "uuid" = '7563076e-f4ed-4f91-886e-f20e73165c1c'::uuid WHERE "uuid" IS NULL; SET CONSTRAINTS ALL IMMEDIATE
ALTER TABLE "umap_datalayer" ALTER COLUMN "uuid" SET NOT NULL
ALTER TABLE "umap_datalayer" ADD CONSTRAINT "umap_datalayer_uuid_5cb47aed_pk" PRIMARY KEY ("uuid")
ALTER TABLE "umap_datalayer" ALTER COLUMN "uuid" DROP DEFAULT |
e72b674
to
1d5ac14
Compare
In order to use the Django JSON Encoder by default.
🎉 |
datalayer.id
todatalayer.old_id
Resources