1
0
mirror of https://github.com/mgerb/classic-wow-forums synced 2026-01-09 16:42:49 +00:00

create thread migration

This commit is contained in:
2018-01-01 20:50:50 -06:00
parent e77288d40e
commit 3a61151191
3 changed files with 48 additions and 0 deletions

28
lib/myapp/data/thread.ex Normal file
View 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

View File

@@ -9,6 +9,8 @@ defmodule MyApp.Data.User do
schema "user" do
field :battle_net_id, :integer
field :battletag, :string
has_many :threads, Data.Thread
timestamps()
end

View 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