Ruby: Rails migrations

This documentation is part of the Learning Ruby guide. View the full guide here: A comprehensive Ruby and Rails guide.

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use Ruby cloud solution that provides a host of benefits, including:

  • Deploy your application in seconds with a simple git push.
  • Use your own domain name and benefit from the automatic configuration of HTTPS certificates for enhanced security.
  • Enjoy peace of mind with automatic backups, one-click updates, and straightforward, transparent, and predictable pricing.
  • Get optimal performance and robust security thanks to a private and dedicated VM.

Save time and simplify your life: it only takes 5 minutes to try Stackhero's Ruby cloud hosting solution!

Migrations allow you to evolve your database schema in a consistent and verifiable way. They use a Ruby DSL, so you do not have to write raw SQL by hand, making your schema changes database-independent. Here is how you can create and run a migration:

  1. Create a new migration:

    rails generate migration MigrationName
    
  2. In the generated migration file (db/migrate/):

    class MigrationName < ActiveRecord::Migration[6.0]
      def change
        add_column :table_name, :column_name, :type
        remove_column :table_name, :column_name
      end
    end