summaryrefslogtreecommitdiff
path: root/priv/repo/migrations/20200607112923_change_chat_id_to_flake.exs
blob: f14e269ca4cf86b95eb85076307451b4161f5ec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
defmodule Pleroma.Repo.Migrations.ChangeChatIdToFlake do
  use Ecto.Migration

  def up do
    execute("""
    alter table chats
    drop constraint chats_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)
    """)

    execute("""
    alter table chat_message_references
    alter column chat_id set data type uuid using cast( lpad( to_hex(chat_id), 32, '0') as uuid),
    add constraint chat_message_references_chat_id_fkey foreign key (chat_id) references chats(id) on delete cascade
    """)
  end

  def down do
    :ok
  end
end