Last active
December 18, 2015 04:19
-
-
Save eamonn-webster/5724995 to your computer and use it in GitHub Desktop.
find and execute trove migrations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load all migrations | |
Dir[Rails.root.join('db/migrate/*.rb')].each { |f| require f } | |
#find the trove migrations classes | |
# and the corresponding file | |
# sort by file | |
# instantiate | |
# and invoke change | |
# rescuing from any exception. | |
trove_migrations = Trove::BaseMigration.subclasses.collect { |c| | |
[c] + Dir[Rails.root.join("db/migrate/*#{c.name.tableize.singularize.gsub('trofe','trove')}*.rb")] | |
}.sort{ |a, b| a[1] <=> b[1] }.collect{ |pair| pair[0] } | |
trove_migrations.each { |c| | |
begin | |
mig = c.new | |
if mig.respond_to? :change | |
mig.change | |
else | |
mig.up | |
end | |
rescue | |
end | |
} | |
# TODO dump schema to trove_schema.rb |
- trofe is the singular of trove!
- yes I spotted that
- true but I'm lazy...
- we need to load them all to find which are subclasses of Trove::BaseMigration. However we could adopt the rule that all and only all trove migrations started (or ended) with trove.
Next step would be to dump the schema,
then at start of tests create the trove schema from trove_schema.rb
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
up
, notchange
.up
instead ofchange
, or that the migration failed because you already have the table, etc.