mirror of
https://github.com/mgerb/classic-wow-forums
synced 2026-01-11 09:32:51 +00:00
create thread migration
This commit is contained in:
28
lib/myapp/data/thread.ex
Normal file
28
lib/myapp/data/thread.ex
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
defmodule MyApp.Data.Thread do
|
||||||
|
use Ecto.Schema
|
||||||
|
import Ecto.Query
|
||||||
|
import Ecto.Changeset
|
||||||
|
alias MyApp.Repo
|
||||||
|
alias MyApp.Data
|
||||||
|
|
||||||
|
@derive {Poison.Encoder, except: [:__meta__]}
|
||||||
|
schema "thread" do
|
||||||
|
field :title, :string
|
||||||
|
field :content, :string
|
||||||
|
field :view_count, :integer
|
||||||
|
field :user_id, :integer
|
||||||
|
field :last_reply_id, :integer
|
||||||
|
field :sticky, :boolean, default: false
|
||||||
|
field :locked, :boolean, default: false
|
||||||
|
|
||||||
|
belongs_to :user, Data.User, define_field: false
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
def changeset(thread, params \\ %{}) do
|
||||||
|
thread
|
||||||
|
|> cast(params, [:title, :content, :user_id, :view_count, :last_reply_id, :sticky, :locked])
|
||||||
|
|> validate_required([:title, :content, :user_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -9,6 +9,8 @@ defmodule MyApp.Data.User do
|
|||||||
schema "user" do
|
schema "user" do
|
||||||
field :battle_net_id, :integer
|
field :battle_net_id, :integer
|
||||||
field :battletag, :string
|
field :battletag, :string
|
||||||
|
|
||||||
|
has_many :threads, Data.Thread
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
18
priv/repo/migrations/20180102015706_create_thread.exs
Normal file
18
priv/repo/migrations/20180102015706_create_thread.exs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
defmodule MyApp.Repo.Migrations.CreateThread do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
create table(:thread) do
|
||||||
|
add :title, :string
|
||||||
|
add :content, :string
|
||||||
|
add :view_count, :integer
|
||||||
|
add :user_id, references(:user)
|
||||||
|
add :last_reply_id, :integer
|
||||||
|
add :sticky, :boolean
|
||||||
|
add :locked, :boolean
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user