Created
January 23, 2017 22:15
-
-
Save mAlishera/42c755a2ec02efb80d936cf2e42cd3be to your computer and use it in GitHub Desktop.
Composite primary key in Ecto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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