Skip to content

Commit 4aab2f6

Browse files
committed
simplify and structure migration code, split big function to small functions
1 parent 2f6e3fb commit 4aab2f6

File tree

7 files changed

+232
-227
lines changed

7 files changed

+232
-227
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/deps
44
erl_crash.dump
55
*.ez
6+
mix.lock

README.md

+47
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,50 @@ EctoMigrate
22
===========
33

44
**TODO: Add description**
5+
6+
```elixir
7+
8+
# Configuration for Repo, only for iex try taste, please use supervisor in your application
9+
:application.set_env(:example, Repo, [adapter: Ecto.Adapters.MySQL, database: "example", username: "root"])
10+
defmodule Repo, do: (use Ecto.Repo, otp_app: :example)
11+
Repo.start_link
12+
import Ecto.Query
13+
14+
defmodule Weather do # is for later at now
15+
use Ecto.Model
16+
17+
schema "weather" do
18+
field :city
19+
field :temp_lo, :integer
20+
field :temp_hi, :integer
21+
field :prcp, :float, default: 0.0
22+
end
23+
end
24+
25+
Ecto.Migration.Auto.migrate(Repo, Weather)
26+
27+
%Weather{city: "Berlin", temp_lo: 20, temp_hi: 25} |> Repo.insert
28+
Repo.all(from w in Weather, where: w.city == "Berlin")
29+
30+
```
31+
32+
Lets redefine the same model in a shell and migrate it
33+
34+
```elixir
35+
36+
defmodule Weather do # is for later at now
37+
use Ecto.Model
38+
39+
schema "weather" do
40+
field :city
41+
field :temp_lo, :integer
42+
field :temp_hi, :integer
43+
field :prcp, :float, default: 0.0
44+
field :wind, :float, default: 0.0
45+
end
46+
end
47+
48+
Ecto.Migration.Auto.migrate(Repo, Weather)
49+
Repo.all(from w in Weather, where: w.city == "Berlin")
50+
51+
```

lib/ecto/migration.ex

-207
This file was deleted.

0 commit comments

Comments
 (0)