Added Schemas
parent
251b4490f3
commit
dc54b69c56
|
@ -32,3 +32,5 @@ npm-debug.log
|
|||
# we ignore priv/static. You may want to comment
|
||||
# this depending on your deployment strategy.
|
||||
/priv/static/
|
||||
|
||||
\#*#
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
defmodule Charbase.Changelog do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "changelog" do
|
||||
field :text, :string
|
||||
field :type, :string
|
||||
field :character_id, :id
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@doc false
|
||||
def changeset(changelog, attrs) do
|
||||
changelog
|
||||
|> cast(attrs, [:type, :text])
|
||||
|> validate_required([:type, :text])
|
||||
end
|
||||
end
|
|
@ -0,0 +1,20 @@
|
|||
defmodule Charbase.Character do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "characters" do
|
||||
field :added, :naive_datetime
|
||||
field :json, :string
|
||||
field :name, :string
|
||||
field :user_id, :id
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@doc false
|
||||
def changeset(character, attrs) do
|
||||
character
|
||||
|> cast(attrs, [:name, :json, :added])
|
||||
|> validate_required([:name, :json, :added])
|
||||
end
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
defmodule Charbase.User do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "users" do
|
||||
field :email, :string
|
||||
field :name, :string
|
||||
field :password, :string
|
||||
field :registered, :naive_datetime
|
||||
field :salt, :string
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@doc false
|
||||
def changeset(user, attrs) do
|
||||
user
|
||||
|> cast(attrs, [:name, :email, :password, :salt, :registered])
|
||||
|> validate_required([:name, :email, :password, :salt, :registered])
|
||||
end
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
defmodule Charbase.Repo.Migrations.CreateUsers do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:users) do
|
||||
add :name, :string
|
||||
add :email, :string
|
||||
add :password, :string
|
||||
add :salt, :string
|
||||
add :registered, :naive_datetime
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
defmodule Charbase.Repo.Migrations.CreateCharacters do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:characters) do
|
||||
add :name, :string
|
||||
add :json, :text
|
||||
add :added, :naive_datetime
|
||||
add :user_id, references(:users, on_delete: :nothing)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index(:characters, [:user_id])
|
||||
end
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
defmodule Charbase.Repo.Migrations.CreateChangelog do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:changelog) do
|
||||
add :type, :string
|
||||
add :text, :text
|
||||
add :character_id, references(:character, on_delete: :nothing)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index(:changelog, [:character_id])
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue