2 title: "Phoenix: Ecto migrations"
12 $ mix ecto.gen.migration update_posts_table
13 creating priv/repo/migrations/20160602085927_update_posts_table.exs
22 Creates a migration (no models).
27 $ mix phoenix.gen.model Message messages user_id:integer content:text
30 This is only for Phoenix 1.2 or older; models aren't available in Phoenix 1.3+.
35 $ mix phx.gen.context Images Album albums title:string subtitle:string privacy:string
38 ## Migration functions
43 create table(:documents) do
45 add :title, :string, size: 40
46 add :title, :string, default: "Hello"
47 add :title, :string, default: fragment("now()")
48 add :title, :string, null: false
53 add :price, :decimal, precision: 10, scale: 2
54 add :published_at, :utc_datetime
55 add :group_id, references(:groups)
58 timestamps # inserted_at and updated_at
61 create_if_not_exists table(:documents) do: ... end
67 alter table(:posts) do
75 rename table(:posts), :title, to: :summary
76 rename table(:posts), to: table(:new_posts)
80 drop table(:documents)
81 drop_if_exists table(:documents)
86 table(:weather, prefix: :north_america)
92 create index(:posts, [:slug], concurrently: true)
93 create unique_index(:posts, [:slug])
94 drop index(:posts, [:name])
100 execute "UPDATE posts SET published_at = NULL"
101 execute create: "posts", capped: true, size: 1024
106 - [Ecto.Migration](http://devdocs.io/phoenix/ecto/ecto.migration)