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
52 add :price, :float, precision: 10, scale: 2
53 add :published_at, :utc_datetime
54 add :group_id, references(:groups)
57 timestamps # inserted_at and updated_at
60 create_if_not_exists table(:documents) do: ... end
66 alter table(:posts) do
74 rename table(:posts), :title, to: :summary
75 rename table(:posts), to: table(:new_posts)
79 drop table(:documents)
80 drop_if_exists table(:documents)
85 table(:weather, prefix: :north_america)
91 create index(:posts, [:slug], concurrently: true)
92 create unique_index(:posts, [:slug])
93 drop index(:posts, [:name])
99 execute "UPDATE posts SET published_at = NULL"
100 execute create: "posts", capped: true, size: 1024
105 - [Ecto.Migration](http://devdocs.io/phoenix/ecto/ecto.migration)