Skip to content

Instantly share code, notes, and snippets.

@mAlishera
Created January 23, 2017 22:15
Show Gist options
  • Save mAlishera/42c755a2ec02efb80d936cf2e42cd3be to your computer and use it in GitHub Desktop.
Save mAlishera/42c755a2ec02efb80d936cf2e42cd3be to your computer and use it in GitHub Desktop.
Composite primary key in Ecto
defmodule Messaging.Repo.Migrations.CreateGroupChatVersions do
use Ecto.Migration
def change do
create table(:group_chat_versions, primary_key: false) do
add :group_chat_id, :uuid, primary_key: true
add :version, :integer, primary_key: true
timestamps
end
create unique_index(:group_chat_versions, [:version, :group_chat_id])
end
end
defmodule Messaging.GroupChatVersion do
use Messaging.Web, :model
@primary_key false
schema "group_chat_versions" do
field :version, :integer, primary_key: true
field :group_chat_id, UUID5, primary_key: true
timestamps
end
@required_fields ~w(version group_chat_id)
@optional_fields ~w()
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment