Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs]: Add a note about how to generate migrations #273

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions content/v2.2/cli-commands/generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Hanami 2.1 provides a few generators:
$ bundle exec hanami generate --help
Commands:
hanami generate action NAME
hanami generate migration NAME
hanami generate part NAME
hanami generate slice NAME
hanami generate view NAME
Expand All @@ -30,6 +31,22 @@ Use the `--help` option to access all accepted options:
$ bundle exec hanami generate action --help
```


### hanami generate migration

Generates a [migration](v2.2/database/migrations/):

```shell
$ bundle exec hanami generate migration create_posts
```

Use the `--help` option to access all accepted options:

```shell
$ bundle exec hanami generate migration --help
```


### hanami generate part

Generates a view [part](/v2.2/views/parts/):
Expand Down
10 changes: 10 additions & 0 deletions content/v2.2/database/migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ config/db/migrate
└── 20240717170318_add_published_at_to_posts.rb
```

## Generating migrations

Migrations can be generated via the Hanami CLI like so:

```
$ hanami generate migration create_posts
```

Which will create a timestamped migration with that looks roughly like this: `config/db/migrate/20240717170227_create_posts.rb`

## Direction

Migration files are bi-directional, they define schema changes *forward* and *backward*, or `up` and `down` in Sequel’s syntax. This is important, in case your migration changes cause a problem you will want to roll them back as quickly as possible, and requiring a fresh migration to do this may take too much time.
Expand Down