lib/strong_migrations/migration.rb in strong_migrations-0.2.0 vs lib/strong_migrations/migration.rb in strong_migrations-0.2.1

- old
+ new

@@ -26,24 +26,36 @@ raise_error :rename_table when :rename_column raise_error :rename_column when :add_index columns = args[1] - if columns.is_a?(Array) && columns.size > 3 + options = args[2] || {} + if columns.is_a?(Array) && columns.size > 3 && !options[:unique] raise_error :add_index_columns end - 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 unless options[:default].nil? - raise_error :add_column_json if type.to_s == "json" + if type.to_s == "json" && postgresql? + if postgresql_version >= 90400 + raise_error :add_column_json + else + raise_error :add_column_json_legacy + end + end when :change_column - raise_error :change_column + safe = false + # assume Postgres 9.1+ since previous versions are EOL + if postgresql? && args[2].to_s == "text" + column = connection.columns(args[0]).find { |c| c.name.to_s == args[1].to_s } + safe = column && column.type == :string + end + raise_error :change_column unless safe when :create_table options = args[1] || {} raise_error :create_table if options[:force] when :add_reference options = args[2] || {} @@ -71,9 +83,13 @@ private def postgresql? %w(PostgreSQL PostGIS).include?(connection.adapter_name) + end + + def postgresql_version + @postgresql_version ||= connection.execute("SHOW server_version_num").first["server_version_num"].to_i end def version_safe? version && version <= StrongMigrations.start_after end