Skip to content

Commit

Permalink
Add docs for :identity key (#516)
Browse files Browse the repository at this point in the history
* Add docs for :identity key

* Apply suggestions from code review

* Update lib/ecto/migration.ex

Co-authored-by: Greg Rychlewski <[email protected]>

---------

Co-authored-by: José Valim <[email protected]>
Co-authored-by: Greg Rychlewski <[email protected]>
  • Loading branch information
3 people committed May 11, 2023
1 parent d0b2323 commit 859501d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/ecto/migration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ defmodule Ecto.Migration do
config :app, App.Repo, migration_primary_key: false
For Postgres version >= 10 `:identity` key may be used.
By default, all :identity column will be bigints. You may provide optional
parameters for `:start_value` and `:increment` to customize the created
sequence. Config example:
config :app, App.Repo, migration_primary_key: [type: :identity]
* `:migration_foreign_key` - By default, Ecto uses the `primary_key` type
for foreign keys when `references/2` is used, but you can configure it via:
Expand Down Expand Up @@ -668,6 +675,10 @@ defmodule Ecto.Migration do
add :price, :decimal
end
create table("users", primary_key: false) do
add :id, :identity, primary_key: true, start_value: 100, increment: 20
end
## Options
* `:primary_key` - when `false`, a primary key field is not generated on table
Expand Down Expand Up @@ -1035,6 +1046,10 @@ defmodule Ecto.Migration do
* `:comment` - adds a comment to the added column.
* `:after` - positions field after the specified one. Only supported on MySQL,
it is ignored by other databases.
* `:start_value` - option for `:identity` key, represents initial value in sequence
generation. Default is defined by the database.
* `:increment` - option for `:identity` key, represents increment value for
sequence generation. Default is defined by the database.
"""
def add(column, type, opts \\ []) when is_atom(column) and is_list(opts) do
Expand Down

0 comments on commit 859501d

Please sign in to comment.