-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates migration and schema for comments table
- Loading branch information
1 parent
4f9b4ea
commit 3818a4e
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
priv/repo/test_app/migrations/20190301105228_create_comments.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
defmodule Alog.Repo.Migrations.CreateComments do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:comments, primary_key: false) do | ||
# cid & entry_id need to be removed later as they should be handled in execute_ddl I believe | ||
add(:cid, :string, primary_key: true) | ||
add(:entry_id, :string) | ||
add(:comment, :string) | ||
add(:deleted, :boolean, default: false) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule Alog.TestApp.Comment do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
# I'd imagine we'll change string as the type but | ||
@primary_key {:cid, :string, autogenerate: false} | ||
schema "users" do | ||
field(:entry_id, :string) | ||
field(:comment, :string) | ||
field(:deleted, :boolean, default: false) | ||
end | ||
|
||
def changeset(comment_struct, attrs \\ %{}) do | ||
comment_struct | ||
|> cast(attrs, [:cid, :entry_id, :comment, :deleted]) | ||
end | ||
end |