First
[anni] / priv / repo / migrations / 20200607112923_change_chat_id_to_flake.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Repo.Migrations.ChangeChatIdToFlake do
6   use Ecto.Migration
7
8   def up do
9     execute("""
10     alter table chats
11     drop constraint chats_pkey cascade,
12     alter column id drop default,
13     alter column id set data type uuid using cast( lpad( to_hex(id), 32, '0') as uuid),
14     add primary key (id)
15     """)
16
17     execute("""
18     alter table chat_message_references
19     alter column chat_id set data type uuid using cast( lpad( to_hex(chat_id), 32, '0') as uuid),
20     add constraint chat_message_references_chat_id_fkey foreign key (chat_id) references chats(id) on delete cascade
21     """)
22   end
23
24   def down do
25     :ok
26   end
27 end