Database migrations, which are often necessary when updates to the database schema are required, form an integral part of the Ruby on Rails development process. Before initiating these migrations on your own, it’s highly recommended to familiarize yourself with the official documentation (Active Record Migrations).
To generate a migration, use the following command in your terminal:
docker-compose run --rm web bundle exec rails generate migration [MIGRATION_NAME]
[MIGRATION_NAME]should be prefixed with one of: Create, Add, Remove or Update. eg.CreateNewTableorAddNewColumnToTable.
Next, you’ll need to modify the generated migration class file according to the specific changes your migration requires. You can find examples of this within the db/migrate directory in the project.
To run your migration, use:
docker-compose run --rm web bundle exec rails db:migrate RAILS_ENV=[ENVIRONMENT]
Replace
[ENVIRONMENT]with the name of the environment where you want the migration run (eg. development, staging, production).