Skip to content

Instantly share code, notes, and snippets.

@jschoch
Created February 6, 2014 14:44
Show Gist options
  • Save jschoch/8845509 to your computer and use it in GitHub Desktop.
Save jschoch/8845509 to your computer and use it in GitHub Desktop.
ecto migration
iex(2)> defmodule MyApp.MigrationExample do
...(2)> use Ecto.Migration
...(2)>
...(2)> def up do
...(2)> "CREATE TABLE user(id serial PRIMARY_KEY, username text)"
...(2)> end
...(2)>
...(2)> def down do
...(2)> "DROP TABLE user"
...(2)> end
...(2)> end
{:module, MyApp.MigrationExample,
<<70, 79, 82, 49, 0, 0, 8, 200, 66, 69, 65, 77, 65, 116, 111, 109, 0, 0, 0, 144, 0, 0, 0, 14, 29, 69, 108, 105, 120, 105, 114, 46, 77, 121, 65, 112, 112, 46, 77, 105, 103, 114, 97, 116, 105, 111, 110, 69, 120, 97, ...>>,
{:down, 0}}
iex(3)> Ecto.Migrator.up(Repo, 20080906120000, MyApp.MigrationExample)
** (Postgrex.Error) ERROR (42601): syntax error at or near "user"
lib/ecto/adapters/postgres/worker.ex:15: Ecto.Adapters.Postgres.Worker.query!/2
lib/ecto/adapters/postgres.ex:238: Ecto.Adapters.Postgres.use_worker/2
lib/ecto/adapters/postgres.ex:359: anonymous fn/3 in Ecto.Adapters.Postgres.run_commands/3
(elixir) lib/enum.ex:517: Enum."-each/2-lists^foreach/1-0-"/2
(elixir) lib/enum.ex:517: Enum.each/2
lib/ecto/adapters/postgres.ex:207: Ecto.Adapters.Postgres.transaction/2
lib/ecto/adapters/postgres.ex:357: Ecto.Adapters.Postgres.run_commands/3
iex(3)> Repo.migrate_up(Repo, 20080906120000, "CREATE TABLE users(id serial, name text)")
** (UndefinedFunctionError) undefined function: Repo.migrate_up/3
(ecto_test) Repo.migrate_up(Repo, 20080906120000, "CREATE TABLE users(id serial, name text)")
iex(3)> MyApp.MigrationExample.
__migration__/0 down/0 up/0
iex(3)> MyApp.MigrationExample.up
"CREATE TABLE user(id serial PRIMARY_KEY, username text)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment