class Pronto::RailsMigrations
Constants
- VERSION
Public Instance Methods
run()
click to toggle source
# File lib/pronto/rails_migrations.rb, line 3 def run return [] unless migration_patches? messages = [] if other_patches? patch = migration_patches.first messages << message( patch, 'Run migrations in a separate PR from application code changes.' ) end messages + bad_structure_sql_messages end
Private Instance Methods
bad_structure_sql_messages()
click to toggle source
# File lib/pronto/rails_migrations.rb, line 33 def bad_structure_sql_messages patch = structure_sql_patches.first return [] unless patch structure_sql = File.read(patch.new_file_full_path) inserts = structure_sql.split("\n").grep(/\('\d+'\)/) unordered_inserts = (inserts.sort != inserts) *all_but_tail, tail = inserts bad_semicolons = all_but_tail.any? { |line| line.end_with?(';') } || !tail.end_with?(';') bad_ending = structure_sql[-4, 4] !~ /[^\n]\n\n\n/ messages = [] if unordered_inserts messages << message( patch, '`schema_migrations` insert values are not ordered by timestamp.' ) end if bad_semicolons messages << message( patch, '`schema_migrations` inserts must end with comma (`,`), ' \ 'last insert must end with semicolon (`;`).' ) end messages << message(patch, '`db/structure.sql` must end with 2 empty lines.') if bad_ending messages end
message(patch, text)
click to toggle source
# File lib/pronto/rails_migrations.rb, line 66 def message(patch, text) path = patch.delta.new_file[:path] line = patch.added_lines.first Message.new(path, line, :warning, text, nil, self.class) end
migration_patch?(patch)
click to toggle source
# File lib/pronto/rails_migrations.rb, line 76 def migration_patch?(patch) path = patch.new_file_full_path.to_s /db.(schema.rb|structure.sql|migrate)/ =~ path end
migration_patches()
click to toggle source
# File lib/pronto/rails_migrations.rb, line 25 def migration_patches @migration_patches ||= @patches.select { |patch| migration_patch?(patch) } end
migration_patches?()
click to toggle source
# File lib/pronto/rails_migrations.rb, line 21 def migration_patches? migration_patches.any? end
other_patches?()
click to toggle source
# File lib/pronto/rails_migrations.rb, line 29 def other_patches? @patches.reject { |patch| migration_patch?(patch) }.any? end
structure_sql_patches()
click to toggle source
# File lib/pronto/rails_migrations.rb, line 72 def structure_sql_patches @patches.select { |patch| patch.new_file_full_path.to_s =~ /structure\.sql/ } end