Created
June 11, 2021 01:42
-
-
Save mazz/c45d499b8049aacc43e9d894d868168f to your computer and use it in GitHub Desktop.
This file contains 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 FaithfulWord.Repo.Migrations.CreateUsersAuthTables do | |
use Ecto.Migration | |
def change do | |
execute "CREATE EXTENSION IF NOT EXISTS citext", "" | |
create table(:users, primary_key: false) do | |
add :id, :binary_id, primary_key: true | |
add :email, :citext, null: false | |
add :username, :citext | |
add :name, :citext | |
add :phone_number, :citext | |
add :confirmed_at, :naive_datetime | |
add :orgs_registered, {:array, :integer}, default: [], null: false | |
add :orgs_confirmed, {:array, :integer}, default: [], null: false | |
add :orgs_authorized, {:array, :integer}, default: [], null: false | |
add :locale, :string, null: true | |
add :uuid, :uuid | |
add :role, :string, null: false | |
add :status, :string, null: false | |
timestamps(type: :utc_datetime_usec) | |
end | |
create unique_index(:users, [:email]) | |
create unique_index(:users, [:phone_number]) | |
create unique_index(:users, [:username]) | |
create index(:users, [:uuid]) | |
create table(:users_tokens) do | |
add :user_id, references(:users, on_delete: :delete_all, type: :binary_id), null: false | |
add :token, :binary, null: false | |
add :context, :string, null: false | |
add :org_id, references(:orgs, on_delete: :delete_all), null: false | |
add :sent_to, :string | |
timestamps(updated_at: false) | |
end | |
# create index(:users_tokens, [:user_id]) | |
create unique_index(:users_tokens, [:context, :token]) | |
end | |
end |
This file contains 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
@primary_key {:id, :binary_id, autogenerate: true} | |
@foreign_key_type :binary_id | |
schema "users" do | |
field :email, :string | |
field :username, :string | |
field :name, :string | |
field :phone_number, :string | |
field :confirmed_at, :naive_datetime | |
... |
This file contains 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
schema "users_tokens" do | |
field :token, :binary | |
field :context, :string | |
field :sent_to, :string | |
field :org_id, :integer | |
belongs_to :user, FaithfulWord.Schema.User | |
timestamps(updated_at: false) | |
end | |
... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment