aboutsummaryrefslogtreecommitdiff
path: root/priv
diff options
context:
space:
mode:
Diffstat (limited to 'priv')
-rw-r--r--priv/repo/migrations/20211218181632_change_object_id_to_flake.exs43
1 files changed, 43 insertions, 0 deletions
diff --git a/priv/repo/migrations/20211218181632_change_object_id_to_flake.exs b/priv/repo/migrations/20211218181632_change_object_id_to_flake.exs
new file mode 100644
index 000000000..3eebe3ef2
--- /dev/null
+++ b/priv/repo/migrations/20211218181632_change_object_id_to_flake.exs
@@ -0,0 +1,43 @@
+defmodule Pleroma.Repo.Migrations.ChangeObjectIdToFlake do
+ @moduledoc """
+ Convert object IDs to FlakeIds.
+ Fortunately only a few tables have a foreign key to objects. Update them.
+ """
+ use Ecto.Migration
+
+ def up do
+ # Switch object IDs to FlakeIds
+ execute("""
+ alter table objects
+ drop constraint objects_pkey cascade,
+ alter column id drop default,
+ alter column id set data type uuid using cast( lpad( to_hex(id), 32, '0') as uuid),
+ add primary key (id)
+ """)
+
+ # Update chat message foreign key
+ execute("""
+ alter table chat_message_references
+ alter column object_id set data type uuid using cast( lpad( to_hex(object_id), 32, '0') as uuid),
+ add constraint chat_message_references_object_id_fkey foreign key (object_id) references objects(id) on delete cascade
+ """)
+
+ # Update delivery foreign key
+ execute("""
+ alter table deliveries
+ alter column object_id set data type uuid using cast( lpad( to_hex(object_id), 32, '0') as uuid),
+ add constraint deliveries_object_id_fkey foreign key (object_id) references objects(id)
+ """)
+
+ # Update hashtag many-to-many foreign key
+ execute("""
+ alter table hashtags_objects
+ alter column object_id set data type uuid using cast( lpad( to_hex(object_id), 32, '0') as uuid),
+ add constraint hashtags_objects_object_id_fkey foreign key (object_id) references objects(id) on delete cascade
+ """)
+ end
+
+ def down do
+ :ok
+ end
+end