Module: DynamicMigrations::Postgres::Server::Database::Differences::ToMigrations::Extensions

Included in:
DynamicMigrations::Postgres::Server::Database::Differences::ToMigrations
Defined in:
lib/dynamic_migrations/postgres/server/database/differences/to_migrations/extensions.rb

Instance Method Summary collapse

Instance Method Details

#process_extension(extension_name, configuration_extension, database_extension) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dynamic_migrations/postgres/server/database/differences/to_migrations/extensions.rb', line 10

def process_extension extension_name, configuration_extension, database_extension
  # if the extension exists in the configuration but not in the database
  # then we have to create it
  if configuration_extension[:exists] == true && !database_extension[:exists]
    log.info "Extension `#{extension_name}` exists in configuration but not in the database"
    # a migration to create the extension
    @generator.enable_extension extension_name

  # if the extension exists in the database but not in the configuration
  # then we need to delete it
  elsif database_extension[:exists] == true && !configuration_extension[:exists]
    log.info "Extension `#{extension_name}` exists in database but not in the configuration"
    # a migration to drop the extension
    if Postgres.remove_unused_extensions?
      @generator.disable_extension extension_name
    else
      log.warn "Skipping removal of extension `#{extension_name}` due to configuration setting"
    end
  end
end