Skip to content

Commit

Permalink
Patched 'db:migrate' task no longer raises if schema file is wacky
Browse files Browse the repository at this point in the history
If there are no 'add_foreign_key' statements around to preserve,
it will display a message to that effect rather than raising
an exception.
  • Loading branch information
tjgrathwell committed Apr 28, 2015
1 parent 2c090fa commit 895a45f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/tasks/db.rake
Expand Up @@ -18,8 +18,18 @@ db_namespace = namespace :db do

unless foreign_keys_supported
new_schema_content = File.read(filename)
fk_rows = existing_schema_content.match(/.*?([ ]+add_foreign.+\nend\n$)/m)[1]
File.write(filename, new_schema_content.sub(/end\n\Z/m, fk_rows))
fk_rows = existing_schema_content.match(/.*?([ ]+add_foreign.+\nend\n$)/m).try(:[], 1)
if fk_rows
File.write(filename, new_schema_content.sub(/end\n\Z/m, fk_rows))
else
puts <<-EOT.strip_heredoc
No 'add_foreign_key' statements were found in schema.rb.
Try checking out an older version of the schema and running a full
rake db:drop
rake db:create
rake db:migrate
EOT
end
end

db_namespace['schema:dump'].reenable
Expand Down

0 comments on commit 895a45f

Please sign in to comment.