diff --git a/lib/nulla/user.ex b/lib/nulla/user.ex new file mode 100644 index 0000000..a8abb7e --- /dev/null +++ b/lib/nulla/user.ex @@ -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 diff --git a/priv/repo/migrations/20250530110822_create_users.exs b/priv/repo/migrations/20250530110822_create_users.exs new file mode 100644 index 0000000..48fa01a --- /dev/null +++ b/priv/repo/migrations/20250530110822_create_users.exs @@ -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