-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
154 additions
and
11 deletions.
There are no files selected for viewing
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
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
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
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,23 @@ | ||
defmodule Append.Address do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
|
||
schema "addresses" do | ||
field :address_line_1, :string | ||
field :address_line_2, :string | ||
field :city, :string | ||
field :name, :string | ||
field :postcode, :string | ||
field :tel, :string | ||
|
||
timestamps() | ||
end | ||
|
||
@doc false | ||
def changeset(address, attrs) do | ||
address | ||
|> cast(attrs, [:name, :address_line_1, :address_line_2, :city, :postcode, :tel]) | ||
|> validate_required([:name, :address_line_1, :address_line_2, :city, :postcode, :tel]) | ||
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
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,23 @@ | ||
defmodule Append.Repo.Migrations.CreateAddresses do | ||
use Ecto.Migration | ||
|
||
# Get name of our Ecto Repo module from our config | ||
@repo :append |> Application.get_env(:ecto_repos) |> List.first() | ||
# Get username of Ecto Repo from our config | ||
@db_user Application.get_env(:append, @repo)[:username] | ||
|
||
def change do | ||
create table(:addresses) do | ||
add(:name, :string) | ||
add(:address_line_1, :string) | ||
add(:address_line_2, :string) | ||
add(:city, :string) | ||
add(:postcode, :string) | ||
add(:tel, :string) | ||
|
||
timestamps() | ||
end | ||
|
||
execute("REVOKE UPDATE, DELETE ON TABLE addresses FROM #{@db_user}") | ||
end | ||
end |