Skip to content

Commit

Permalink
add uuid field and avoid replacing id right away
Browse files Browse the repository at this point in the history
  • Loading branch information
filipecabaco committed Oct 12, 2024
1 parent 15249b8 commit a7f3d6a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/realtime/api/message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ defmodule Realtime.Api.Message do
use Ecto.Schema
import Ecto.Changeset

@primary_key {:id, Ecto.UUID, autogenerate: true}
@schema_prefix "realtime"

schema "messages" do
field :uuid, :string
field :topic, :string
field :extension, Ecto.Enum, values: [:broadcast, :presence]
field :payload, :map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ defmodule Realtime.Tenants.Migrations.ChangeMessagesIdType do

def change do
alter table(:messages) do
add_if_not_exists :uuid, :binary_id,
primary_key: true,
default: fragment("gen_random_uuid()")

remove_if_exists :id, :id
add_if_not_exists(:uuid, :uuid, default: fragment("gen_random_uuid()"))
end

rename table(:messages), :uuid, to: :id
end
end

0 comments on commit a7f3d6a

Please sign in to comment.