This is a draft cheat sheet. It is a work in progress and is not finished yet.
Mix tasks
ecto.create |
Creates the repository storage |
ecto.create -r Custom.Repo |
ecto.drop |
Drops the repository storage |
ecto.drop -r Custom.Repo |
ecto.dump |
Dumps the repository database structure |
ecto.dump -r Custom.Repo |
ecto.dump -d /path/to/file |
ecto.gen.migration |
Generates a new migration for the repo |
ecto.gen.migration add_posts_table |
ecto.gen.migration add_posts_table -r Custom.Repo |
ecto.gen.repo |
Generates a new repository |
ecto.gen.repo -r Custom.Repo |
ecto.load |
Loads previously dumped database structure |
ecto.load -r Custom.Repo |
ecto.load -d /path/to/file |
ecto.migrate |
Runs the repository migrations |
ecto.migrate -r Custom.Repo |
ecto.migrate -n(--step) 3 |
ecto.migrate -v(--to) 20080906120000 |
ecto.rollback |
Rolls back the repository migrations |
ecto.rollback -r Custom.Repo |
ecto.rollback -n(--step) 3 |
ecto.rollback -v(--to) 20080906120000 |
ecto.rollback --all |
|
|
Migrations
defmodule MyRepo.Migrations.MyMigration do
use Ecto.Migration
def up, do: ...
def down, do: ...
# or
def change, do: ...
end
|
You can use either up/0, down/0
or change/0
Migrations.Change Table
create table(:name) do |
Create table macro |
alter table(:name) do |
Alter table macro |
create_if_not_exist table(:name) do |
Creates table, but not raise an error, if table already exist |
|