Add users schema
This commit is contained in:
parent
9d2137d30f
commit
f61444cffa
2 changed files with 64 additions and 0 deletions
35
lib/nulla/user.ex
Normal file
35
lib/nulla/user.ex
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
defmodule Nulla.User do
|
||||||
|
use Ecto.Schema
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
schema "users" do
|
||||||
|
field :name, :string
|
||||||
|
field :email, :string
|
||||||
|
field :password, :string
|
||||||
|
field :is_moderator, :boolean, default: false
|
||||||
|
|
||||||
|
field :realname, :string
|
||||||
|
field :bio, :string
|
||||||
|
field :location, :string
|
||||||
|
field :birthday, :date
|
||||||
|
field :fields, :map
|
||||||
|
field :follow_approval, :boolean, default: false
|
||||||
|
field :is_bot, :boolean, default: false
|
||||||
|
field :is_discoverable, :boolean, default: true
|
||||||
|
field :is_indexable, :boolean, default: true
|
||||||
|
field :is_memorial, :boolean, default: false
|
||||||
|
field :private_key, :string
|
||||||
|
field :public_key, :string
|
||||||
|
field :avater, :string
|
||||||
|
field :banner, :string
|
||||||
|
|
||||||
|
timestamps(type: :utc_datetime)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
|
def changeset(user, attrs) do
|
||||||
|
user
|
||||||
|
|> cast(attrs, [:name, :email, :password, :is_moderator, :realname, :bio, :location, :birthday, :fields, :follow_approval, :is_bot, :is_discoverable, :is_indexable, :is_memorial, :private_key, :public_key, :avater, :banner])
|
||||||
|
|> validate_required([:name, :email, :password, :is_moderator, :realname, :bio, :location, :birthday, :fields, :follow_approval, :is_bot, :is_discoverable, :is_indexable, :is_memorial, :private_key, :public_key, :avater, :banner])
|
||||||
|
end
|
||||||
|
end
|
29
priv/repo/migrations/20250530110822_create_users.exs
Normal file
29
priv/repo/migrations/20250530110822_create_users.exs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
defmodule Nulla.Repo.Migrations.CreateUsers do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
create table(:users) do
|
||||||
|
add :username, :string, null: false, unique: true
|
||||||
|
add :email, :string
|
||||||
|
add :password, :string
|
||||||
|
add :is_moderator, :boolean, default: false, null: false
|
||||||
|
|
||||||
|
add :realname, :string
|
||||||
|
add :bio, :string
|
||||||
|
add :location, :string
|
||||||
|
add :birthday, :date
|
||||||
|
add :fields, :map
|
||||||
|
add :follow_approval, :boolean, default: false, null: false
|
||||||
|
add :is_bot, :boolean, default: false, null: false
|
||||||
|
add :is_discoverable, :boolean, default: true, null: false
|
||||||
|
add :is_indexable, :boolean, default: true, null: false
|
||||||
|
add :is_memorial, :boolean, default: false, null: false
|
||||||
|
add :private_key, :string, null: false
|
||||||
|
add :public_key, :string, null: false
|
||||||
|
add :avater, :string
|
||||||
|
add :banner, :string
|
||||||
|
|
||||||
|
timestamps(type: :utc_datetime)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue