Skip to content

Conversation

hachi8833
Copy link
Contributor

Motivation / Background

This Pull Request has been created because bin/rails db:prepare is missing in current migration guide since Rails 6.0.

cc: @bensheldon, the author of #45464

Detail

This Pull Request add a description for db:prepare.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]

@rails-bot rails-bot bot added the docs label Oct 4, 2023
Copy link
Contributor

@bensheldon bensheldon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for updating this! I suggested one small tweak.

The `bin/rails db:prepare` command is similar to `bin/rails db:setup`, but it operates idempotently.

* If the database has not been created yet, the command will run as the `bin/rails db:setup` does.
* If the database exists but the tables have not been created, the command will load the schema, run any pending migrations to dump schema, and finally load the seed data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* If the database exists but the tables have not been created, the command will load the schema, run any pending migrations to dump schema, and finally load the seed data.
* If the database exists but the tables have not been created, the command will load the schema, run any pending migrations, dump the updated schema, and finally load the seed data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review! Updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Squashed the commits.

* If both the database and tables exist but the seed data has not been loaded, the command will only load the seed data.
* If the database, tables, and seed data are all in place, the command will do nothing.

NOTE: Once the database, tables, and seed data are all established, the command will not try to reload the seed data, even if the previously loaded seed data or the existing seed file have been altered or deleted. To reload the seed data, you can manually run `bin/rails db:seed`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Can you wrap the docs to 80 characters like the rest of the document?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added hard wrap and squashed.

Review by ChatGPT

Minor fix on db:prepare document

Update by review

Add hard wrap
@eileencodes eileencodes merged commit bced1e1 into rails:main Oct 4, 2023
@hachi8833 hachi8833 deleted the add_doc_db_prepare branch October 4, 2023 11:06
rafaelfranca pushed a commit that referenced this pull request Oct 4, 2023
[ci-skip][Docs]Add description for `db:prepare` command
flavorjones added a commit to flavorjones/rails that referenced this pull request Oct 19, 2024
Introduces a new database config property `seeds` to control whether
seeds are loaded during `db:prepare` which defaults to `true` for
primary database configs and `false otherwise.

Previously, the `db:prepare` task would load seeds whenever a new
database is created, leading to potential loss of data if a database
is added to an existing environment.

Also, update the Active Record Migrations guide to more accurately
describe what the `db:prepare` task does, correcting some
misinformation introduced in rails#49480 along the way.

Closes rails#53348
flavorjones added a commit to flavorjones/rails that referenced this pull request Oct 19, 2024
Introduces a new database config property `seeds` to control whether
seeds are loaded during `db:prepare` which defaults to `true` for
primary database configs and `false otherwise.

Previously, the `db:prepare` task would load seeds whenever a new
database is created, leading to potential loss of data if a database
is added to an existing environment.

Also, update the Active Record Migrations guide to more accurately
describe what the `db:prepare` task does, correcting some
misinformation introduced in rails#49480 along the way.

Closes rails#53348
flavorjones added a commit to flavorjones/rails that referenced this pull request Oct 19, 2024
Introduces a new database config property `seeds` to control whether
seeds are loaded during `db:prepare` which defaults to `true` for
primary database configs and `false otherwise.

Previously, the `db:prepare` task would load seeds whenever a new
database is created, leading to potential loss of data if a database
is added to an existing environment.

Also, update the Active Record Migrations guide to more accurately
describe what the `db:prepare` task does, correcting some
misinformation introduced in rails#49480 along the way.

Closes rails#53348
flavorjones added a commit to flavorjones/rails that referenced this pull request Oct 24, 2024
Introduces a new database config property `seeds` to control whether
seeds are loaded during `db:prepare` which defaults to `true` for
primary database configs and `false otherwise.

Previously, the `db:prepare` task would load seeds whenever a new
database is created, leading to potential loss of data if a database
is added to an existing environment.

Also, update the Active Record Migrations guide to more accurately
describe what the `db:prepare` task does, correcting some
misinformation introduced in rails#49480 along the way.

Closes rails#53348
rafaelfranca pushed a commit to flavorjones/rails that referenced this pull request Oct 25, 2024
Introduces a new database config property `seeds` to control whether
seeds are loaded during `db:prepare` which defaults to `true` for
primary database configs and `false otherwise.

Previously, the `db:prepare` task would load seeds whenever a new
database is created, leading to potential loss of data if a database
is added to an existing environment.

Also, update the Active Record Migrations guide to more accurately
describe what the `db:prepare` task does, correcting some
misinformation introduced in rails#49480 along the way.

Closes rails#53348
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants