@@ -2,3 +2,50 @@ EctoMigrate
2
2
===========
3
3
4
4
** 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
+ ```
0 commit comments