switched to binary ids for db

This commit is contained in:
Adam Piontek 2021-03-05 12:59:41 -05:00
commit 9651887f34
6 changed files with 20 additions and 8 deletions

View file

@ -4,7 +4,8 @@ defmodule Bones73k.Repo.Migrations.CreateUsersAuthTables do
def change do
execute("CREATE EXTENSION IF NOT EXISTS citext", "")
create table(:users) do
create table(:users, primary_key: false) do
add(:id, :binary_id, primary_key: true)
add(:email, :citext, null: false)
add(:hashed_password, :string, null: false)
add(:confirmed_at, :naive_datetime)
@ -13,8 +14,9 @@ defmodule Bones73k.Repo.Migrations.CreateUsersAuthTables do
create(unique_index(:users, [:email]))
create table(:users_tokens) do
add(:user_id, references(:users, on_delete: :delete_all), null: false)
create table(:users_tokens, primary_key: false) do
add(:id, :binary_id, primary_key: true)
add(:user_id, references(:users, type: :binary_id, on_delete: :delete_all), null: false)
add(:token, :binary, null: false)
add(:context, :string, null: false)
add(:sent_to, :string)

View file

@ -2,11 +2,12 @@ defmodule Bones73k.Repo.Migrations.CreateProperties do
use Ecto.Migration
def change do
create table(:properties) do
create table(:properties, primary_key: false) do
add(:id, :binary_id, primary_key: true)
add(:name, :string)
add(:price, :decimal)
add(:description, :text)
add(:user_id, references(:users, on_delete: :nothing))
add(:user_id, references(:users, type: :binary_id, on_delete: :nothing))
timestamps()
end