+
<%= gettext("Activities Enrolled") %>
From 24e377f2552a553d4e692d41b20900f26d221eb2 Mon Sep 17 00:00:00 2001
From: Rui Lopes <76881129+RuiL1904@users.noreply.github.com>
Date: Mon, 14 Aug 2023 16:55:30 +0100
Subject: [PATCH 2/2] Fix users schema (#317)
---
lib/atomic/accounts/user.ex | 9 ++++-----
.../20221014155230_create_users_auth_tables.exs | 6 +++++-
priv/repo/migrations/20230325151547_add_user_data.exs | 2 --
3 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/lib/atomic/accounts/user.ex b/lib/atomic/accounts/user.ex
index 2ef250c97..a2ec48297 100644
--- a/lib/atomic/accounts/user.ex
+++ b/lib/atomic/accounts/user.ex
@@ -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()
diff --git a/priv/repo/migrations/20221014155230_create_users_auth_tables.exs b/priv/repo/migrations/20221014155230_create_users_auth_tables.exs
index d9fb15b08..f7fc7f948 100644
--- a/priv/repo/migrations/20221014155230_create_users_auth_tables.exs
+++ b/priv/repo/migrations/20221014155230_create_users_auth_tables.exs
@@ -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
@@ -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
diff --git a/priv/repo/migrations/20230325151547_add_user_data.exs b/priv/repo/migrations/20230325151547_add_user_data.exs
index b07f76364..1cde65728 100644
--- a/priv/repo/migrations/20230325151547_add_user_data.exs
+++ b/priv/repo/migrations/20230325151547_add_user_data.exs
@@ -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