Generate migrations outside Rails

Viewed 5349

I'm using ActiveRecord outside Rails. I would want a program to generate the skeleton of a migration ( as well as a system to collect and maintain them ).

Can anyone make a suggestion?

5 Answers

I have made a minimal example of how to use active record outside of Rails. Rails migrations (Standalone migrations) in non-Rails (and non Ruby) projects.

https://github.com/euclid1990/rails-migration

(Support Rails >= 5.2)

You can refer Rake file in this repo.

There is another gem called otr-activerecord. This gem provides following tasks:

  • rake db:create
  • rake db:create_migration[name]
  • rake db:drop
  • rake db:environment:set
  • rake db:fixtures:load
  • rake db:migrate
  • rake db:migrate:status
  • rake db:rollback
  • rake db:schema:cache:clear
  • rake db:schema:cache:dump
  • rake db:schema:dump
  • rake db:schema:load
  • rake db:seed
  • rake db:setup
  • rake db:structure:dump
  • rake db:structure:load
  • rake db:version

All you need to do is to install it and add a Rakefile with content

load 'tasks/otr-activerecord.rake'
OTR::ActiveRecord.configure_from_file! 'config/database.yml'

I prefer this gem over active_record_migrations or Standalone Migration because those two gems depend on railties, which is almost the entire Rails. For example, Nokogiri takes a long time to compile, and takes a lot of spaces.

Related