-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migration files and example app created
- Loading branch information
Showing
17 changed files
with
287 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# The directory Mix will write compiled artifacts to. | ||
/_build | ||
|
||
# If you run "mix test --cover", coverage assets end up here. | ||
/cover | ||
|
||
# The directory Mix downloads your dependencies sources to. | ||
/deps | ||
|
||
# Where 3rd-party dependencies like ExDoc output generated docs. | ||
/doc | ||
|
||
# If the VM crashes, it generates a dump, let's ignore it too. | ||
erl_crash.dump | ||
|
||
# Also ignore archive artifacts (built via "mix archive.build"). | ||
*.ez |
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,24 @@ | ||
# Example | ||
|
||
**TODO: Add description** | ||
|
||
## Installation | ||
|
||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed as: | ||
|
||
1. Add `example` to your list of dependencies in `mix.exs`: | ||
|
||
```elixir | ||
def deps do | ||
[{:example, "~> 0.1.0"}] | ||
end | ||
``` | ||
|
||
2. Ensure `example` is started before your application: | ||
|
||
```elixir | ||
def application do | ||
[applications: [:example]] | ||
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,38 @@ | ||
# This file is responsible for configuring your application | ||
# and its dependencies with the aid of the Mix.Config module. | ||
use Mix.Config | ||
|
||
config :example, ecto_repos: [Example.Repo] | ||
|
||
config :example, Example.Repo, | ||
adapter: Ecto.Adapters.Postgres, | ||
database: "papertrail_example", | ||
username: "postgres", | ||
password: "postgres" | ||
|
||
# This configuration is loaded before any dependency and is restricted | ||
# to this project. If another project depends on this project, this | ||
# file won't be loaded nor affect the parent project. For this reason, | ||
# if you want to provide default values for your application for | ||
# 3rd-party users, it should be done in your "mix.exs" file. | ||
|
||
# You can configure for your application as: | ||
# | ||
# config :example, key: :value | ||
# | ||
# And access this configuration in your application as: | ||
# | ||
# Application.get_env(:example, :key) | ||
# | ||
# Or configure a 3rd-party app: | ||
# | ||
# config :logger, level: :info | ||
# | ||
|
||
# It is also possible to import configuration files, relative to this | ||
# directory. For example, you can emulate configuration per environment | ||
# by uncommenting the line below and defining dev.exs, test.exs and such. | ||
# Configuration from the imported file will override the ones defined | ||
# here (which is why it is important to import them last). | ||
# | ||
# import_config "#{Mix.env}.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,28 @@ | ||
defmodule Company do | ||
use Ecto.Schema | ||
|
||
import Ecto | ||
import Ecto.Changeset | ||
import Ecto.Query | ||
|
||
schema "companies" do | ||
field :name, :string | ||
field :is_active, :boolean | ||
field :website, :string | ||
field :city, :string | ||
field :address, :string | ||
field :facebook, :string | ||
field :twitter, :string | ||
field :founded_in, :string | ||
|
||
timestamps | ||
end | ||
|
||
@required_fields ~w() | ||
@optional_fields ~w() | ||
|
||
def changeset(model, params \\ :empty) do | ||
model | ||
|> cast(params, @required_fields, @optional_fields) | ||
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,3 @@ | ||
defmodule Example.Repo do | ||
use Ecto.Repo, otp_app: :example | ||
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,25 @@ | ||
defmodule Person do | ||
use Ecto.Schema | ||
|
||
import Ecto | ||
import Ecto.Changeset | ||
import Ecto.Query | ||
|
||
schema "people" do | ||
field :first_name, :string | ||
field :last_name, :string | ||
field :visit_count, :integer | ||
field :gender, :boolean | ||
field :birthdate, Ecto.Date | ||
|
||
timestamps | ||
end | ||
|
||
@required_fields ~w() | ||
@optional_fields ~w() | ||
|
||
def changeset(model, params \\ :empty) do | ||
model | ||
|> cast(params, @required_fields, @optional_fields) | ||
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,36 @@ | ||
defmodule Example.Mixfile do | ||
use Mix.Project | ||
|
||
def project do | ||
[app: :example, | ||
version: "0.1.0", | ||
elixir: "~> 1.3", | ||
build_embedded: Mix.env == :prod, | ||
start_permanent: Mix.env == :prod, | ||
deps: deps()] | ||
end | ||
|
||
# Configuration for the OTP application | ||
# | ||
# Type "mix help compile.app" for more information | ||
def application do | ||
[applications: [:logger, :postgrex, :ecto]] | ||
end | ||
|
||
# Dependencies can be Hex packages: | ||
# | ||
# {:mydep, "~> 0.3.0"} | ||
# | ||
# Or git/path repositories: | ||
# | ||
# {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"} | ||
# | ||
# Type "mix help deps" for more examples and options | ||
defp deps do | ||
[ | ||
{:postgrex, ">= 0.0.0"}, | ||
{:ecto, "~> 2.0.2"}, | ||
{:poison, "2.1.0"} | ||
] | ||
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,7 @@ | ||
%{"connection": {:hex, :connection, "1.0.3", "3145f7416be3df248a4935f24e3221dc467c1e3a158d62015b35bd54da365786", [:mix], []}, | ||
"db_connection": {:hex, :db_connection, "1.0.0-rc.3", "d9ceb670fe300271140af46d357b669983cd16bc0d01206d7d3222dde56cf038", [:mix], [{:sbroker, "~> 1.0.0-beta.3", [hex: :sbroker, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:connection, "~> 1.0.2", [hex: :connection, optional: false]}]}, | ||
"decimal": {:hex, :decimal, "1.1.2", "79a769d4657b2d537b51ef3c02d29ab7141d2b486b516c109642d453ee08e00c", [:mix], []}, | ||
"ecto": {:hex, :ecto, "2.0.2", "b02331c1f20bbe944dbd33c8ecd8f1ccffecc02e344c4471a891baf3a25f5406", [:mix], [{:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: true]}, {:sbroker, "~> 1.0-beta", [hex: :sbroker, optional: true]}, {:mariaex, "~> 0.7.7", [hex: :mariaex, optional: true]}, {:postgrex, "~> 0.11.2", [hex: :postgrex, optional: true]}, {:db_connection, "~> 1.0-rc.2", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}]}, | ||
"poison": {:hex, :poison, "2.1.0", "f583218ced822675e484648fa26c933d621373f01c6c76bd00005d7bd4b82e27", [:mix], []}, | ||
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []}, | ||
"postgrex": {:hex, :postgrex, "0.11.2", "139755c1359d3c5c6d6e8b1ea72556d39e2746f61c6ddfb442813c91f53487e8", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.0-rc", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]}} |
16 changes: 16 additions & 0 deletions
16
example/priv/repo/migrations/20160715113434_create_versions.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,16 @@ | ||
defmodule Example.Repo.Migrations.CreateVersions do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:versions) do | ||
add :event, :string | ||
add :item_type, :string | ||
add :item_id, :integer | ||
add :item_changes, :map | ||
add :meta, :map | ||
add :originator, :string | ||
|
||
add :inserted_at, :datetime, null: false | ||
end | ||
end | ||
end |
18 changes: 18 additions & 0 deletions
18
example/priv/repo/migrations/20160715113439_create_companies.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,18 @@ | ||
defmodule Example.Repo.Migrations.CreateCompanies do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:companies) do | ||
add :name, :string | ||
add :is_active, :string | ||
add :website, :string | ||
add :city, :string | ||
add :address, :string | ||
add :facebook, :string | ||
add :twitter, :string | ||
add :founded_in, :string | ||
|
||
timestamps | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
example/priv/repo/migrations/20160715113442_create_people.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,15 @@ | ||
defmodule Example.Repo.Migrations.CreatePeople do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:people) do | ||
add :first_name, :string | ||
add :last_name, :string | ||
add :visit_count, :integer | ||
add :gender, :boolean | ||
add :birthdate, :date | ||
|
||
timestamps | ||
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,8 @@ | ||
defmodule ExampleTest do | ||
use ExUnit.Case | ||
doctest Example | ||
|
||
test "the truth" do | ||
assert 1 + 1 == 2 | ||
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 @@ | ||
ExUnit.start() |
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,18 @@ | ||
defmodule Repo.Migrations.AddCompanies do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:companies) do | ||
add :name, :string | ||
add :is_active, :string | ||
add :website, :string | ||
add :city, :string | ||
add :address, :string | ||
add :facebook, :string | ||
add :twitter, :string | ||
add :founded_in, :string | ||
|
||
timestamps | ||
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,15 @@ | ||
defmodule Repo.Migrations.AddPeople do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:people) do | ||
add :first_name, :string | ||
add :last_name, :string | ||
add :visit_count, :integer | ||
add :gender, :boolean | ||
add :birthdate, :date | ||
|
||
timestamps | ||
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