Skip to content

Commit

Permalink
Fix users schema (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruilopesm authored Aug 14, 2023
1 parent 0ea7399 commit 24e377f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
9 changes: 4 additions & 5 deletions lib/atomic/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,23 @@ defmodule Atomic.Accounts.User do
alias Atomic.Uploaders.ProfilePicture

@required_fields ~w(email password)a
@optional_fields ~w(name course_id default_organization_id)a
@optional_fields ~w(name role confirmed_at course_id default_organization_id)a

@roles ~w(admin student)a

schema "users" do
field :email, :string
field :name, :string
field :email, :string
field :password, :string, virtual: true, redact: true
field :hashed_password, :string, redact: true
field :confirmed_at, :naive_datetime
belongs_to :default_organization, Organization

belongs_to :course, Course
field :profile_picture, ProfilePicture.Type
field :role, Ecto.Enum, values: @roles, default: :student
belongs_to :course, Course
belongs_to :default_organization, Organization

has_many :enrollments, Enrollment

many_to_many :organizations, Organization, join_through: Membership

timestamps()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ defmodule Atomic.Repo.Migrations.CreateUsersAuthTables do

create table(:users, primary_key: false) do
add :id, :binary_id, primary_key: true
add :name, :string
add :email, :citext, null: false
add :hashed_password, :string, null: false
add :confirmed_at, :naive_datetime
add :profile_picture, :string

add :role, :string, null: false, default: "student"

add :default_organization_id,
references(:organizations, type: :binary_id, on_delete: :delete_all)

add :role, :string, null: false, default: "student"
timestamps()
end

Expand All @@ -25,6 +28,7 @@ defmodule Atomic.Repo.Migrations.CreateUsersAuthTables do
add :token, :binary, null: false
add :context, :string, null: false
add :sent_to, :string

timestamps(updated_at: false)
end

Expand Down
2 changes: 0 additions & 2 deletions priv/repo/migrations/20230325151547_add_user_data.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ defmodule Atomic.Repo.Migrations.AddUserData do
end

alter table(:users) do
add :name, :string
add :course_id, references(:courses, on_delete: :nothing, type: :binary_id), null: true
add :profile_picture, :string
end
end
end

0 comments on commit 24e377f

Please sign in to comment.