Adding a PostgreSQL extension
When modifying Postgres extensions, these queries must be wrapped in an EXISTS condition. We do this because our development, integration, and production servers get their extensions added outside of the Rails migration system. Without checking for EXISTS, these migrations would fail.
class EnableUnaccentExtension < ActiveRecord::Migration
def up
execute 'CREATE EXTENSION IF NOT EXISTS unaccent SCHEMA shared_extensions;'
end
def down
execute 'DROP EXTENSION IF EXISTS unaccent SCHEMA shared_extensions;'
end
end