Skip to content

Commit

Permalink
Use UUIDs as primary keys instead of sequential integers (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcauchon authored Aug 1, 2023
1 parent 60b1b97 commit 5683b49
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ config :elixir_boilerplate, ElixirBoilerplateWeb.Endpoint,
pubsub_server: ElixirBoilerplate.PubSub,
render_errors: [view: ElixirBoilerplateWeb.Errors, accepts: ~w(html json)]

config :elixir_boilerplate, ElixirBoilerplate.Repo, start_apps_before_migration: [:ssl]
config :elixir_boilerplate, ElixirBoilerplate.Repo,
migration_primary_key: [type: :binary_id, default: {:fragment, "gen_random_uuid()"}],
migration_timestamps: [type: :utc_datetime_usec],
start_apps_before_migration: [:ssl]

config :elixir_boilerplate, Corsica, allow_headers: :all

Expand Down
15 changes: 15 additions & 0 deletions lib/elixir_boilerplate/schema.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule ElixirBoilerplate.Schema do
defmacro __using__(_) do
quote do
use Ecto.Schema

import Ecto.Changeset

alias Ecto.{Schema, UUID}

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
@timestamps_opts [type: :utc_datetime_usec]
end
end
end

0 comments on commit 5683b49

Please sign in to comment.