lib/strong_migrations/migration.rb in strong_migrations-0.1.8 vs lib/strong_migrations/migration.rb in strong_migrations-0.1.9

- old
+ new

@@ -12,11 +12,11 @@ @direction = direction super end def method_missing(method, *args, &block) - unless @safe || ENV["SAFETY_ASSURED"] || is_a?(ActiveRecord::Schema) || @direction == :down + unless @safe || ENV["SAFETY_ASSURED"] || is_a?(ActiveRecord::Schema) || @direction == :down || version_safe? case method when :remove_column raise_error :remove_column when :remove_timestamps raise_error :remove_column @@ -29,18 +29,18 @@ when :add_index columns = args[1] if columns.is_a?(Array) && columns.size > 3 raise_error :add_index_columns end - options = args[2] - if postgresql? && !(options && options[:algorithm] == :concurrently) && !@new_tables.to_a.include?(args[0].to_s) + options = args[2] || {} + if postgresql? && options[:algorithm] != :concurrently && !@new_tables.to_a.include?(args[0].to_s) raise_error :add_index end when :add_column type = args[2] - options = args[3] - raise_error :add_column_default if options && !options[:default].nil? + options = args[3] || {} + raise_error :add_column_default unless options[:default].nil? raise_error :add_column_json if type.to_s == "json" when :change_column raise_error :change_column when :create_table options = args[1] || {} @@ -71,9 +71,13 @@ private def postgresql? %w(PostgreSQL PostGIS).include?(connection.adapter_name) + end + + def version_safe? + version && version <= StrongMigrations.start_after end def raise_error(message_key) message = case message_key