Skip to content

Commit

Permalink
Create a database schema to store the chat history
Browse files Browse the repository at this point in the history
  • Loading branch information
Marta Medio committed Mar 11, 2019
1 parent 816b881 commit 649e43e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/chat/message.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule Chat.Message do
use Ecto.Schema
import Ecto.Changeset


schema "messages" do
field :message, :string
field :name, :string

timestamps()
end

@doc false
def changeset(message, attrs) do
message
|> cast(attrs, [:name, :message])
|> validate_required([:name, :message])
end
end
13 changes: 13 additions & 0 deletions priv/repo/migrations/20190311152318_create_messages.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule Chat.Repo.Migrations.CreateMessages do
use Ecto.Migration

def change do
create table(:messages) do
add :name, :string
add :message, :string

timestamps()
end

end
end

0 comments on commit 649e43e

Please sign in to comment.