rubysinatrasinatra-activerecord

Create a migration to add the `admin` field to the `users` table


How to create migration to add the admin field to the users table with a boolean value and set default to false in Sinatra? I am using Active Record.


Solution

  • It's still just ActiveRecord, this would be no different than using it in Rails.

    class AddAdminToUsers < ActiveRecord::Migration
      def change
        add_column :admin, :boolean, :default => false
      end
    end
    

    You may also want to check out the sinatra-activerecord gem which will give you some extra rake tasks and makes things a little easier.

    Here is also a useful article on using Sinatra with ActiveRecord.

    Sinatra and ActiveRecord