2020-12-15 14:24:14 +01:00
|
|
|
defmodule RecycledCloud.Repo.Migrations.CreateUsersAuthTables do
|
|
|
|
use Ecto.Migration
|
|
|
|
|
|
|
|
def change do
|
|
|
|
execute "CREATE EXTENSION IF NOT EXISTS citext", ""
|
|
|
|
|
|
|
|
create table(:users) do
|
2020-12-21 15:40:19 +01:00
|
|
|
add :username, :citext, null: false
|
2020-12-15 14:24:14 +01:00
|
|
|
add :confirmed_at, :naive_datetime
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
2020-12-21 15:40:19 +01:00
|
|
|
create unique_index(:users, [:username])
|
2020-12-15 14:24:14 +01:00
|
|
|
|
|
|
|
create table(:users_tokens) do
|
|
|
|
add :user_id, references(:users, on_delete: :delete_all), null: false
|
|
|
|
add :token, :binary, null: false
|
|
|
|
add :context, :string, 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
|