forked from AkkomaGang/akkoma
Chats: Change id to flake id.
This commit is contained in:
parent
0365053c8d
commit
1a11f0e453
3 changed files with 27 additions and 1 deletions
|
@ -16,6 +16,8 @@ defmodule Pleroma.Chat do
|
||||||
It is a helper only, to make it easy to display a list of chats with other people, ordered by last bump. The actual messages are retrieved by querying the recipients of the ChatMessages.
|
It is a helper only, to make it easy to display a list of chats with other people, ordered by last bump. The actual messages are retrieved by querying the recipients of the ChatMessages.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@primary_key {:id, FlakeId.Ecto.CompatType, autogenerate: true}
|
||||||
|
|
||||||
schema "chats" do
|
schema "chats" do
|
||||||
belongs_to(:user, User, type: FlakeId.Ecto.CompatType)
|
belongs_to(:user, User, type: FlakeId.Ecto.CompatType)
|
||||||
field(:recipient, :string)
|
field(:recipient, :string)
|
||||||
|
@ -63,6 +65,7 @@ def bump_or_create(user_id, recipient) do
|
||||||
|> changeset(%{user_id: user_id, recipient: recipient})
|
|> changeset(%{user_id: user_id, recipient: recipient})
|
||||||
|> Repo.insert(
|
|> Repo.insert(
|
||||||
on_conflict: [set: [updated_at: NaiveDateTime.utc_now()]],
|
on_conflict: [set: [updated_at: NaiveDateTime.utc_now()]],
|
||||||
|
returning: true,
|
||||||
conflict_target: [:user_id, :recipient]
|
conflict_target: [:user_id, :recipient]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,7 +21,7 @@ defmodule Pleroma.Chat.MessageReference do
|
||||||
|
|
||||||
schema "chat_message_references" do
|
schema "chat_message_references" do
|
||||||
belongs_to(:object, Object)
|
belongs_to(:object, Object)
|
||||||
belongs_to(:chat, Chat)
|
belongs_to(:chat, Chat, type: FlakeId.Ecto.CompatType)
|
||||||
|
|
||||||
field(:unread, :boolean, default: true)
|
field(:unread, :boolean, default: true)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,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
|
Loading…
Reference in a new issue