Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with postgis adapter #65

Open
gap777 opened this issue May 17, 2023 · 1 comment
Open

Incompatible with postgis adapter #65

gap777 opened this issue May 17, 2023 · 1 comment

Comments

@gap777
Copy link

gap777 commented May 17, 2023

Adding gem 'activerecord-postgis-adapter' to your Gemfile and configuring database.yml to use the postgis adapter:

default: &default
  adapter: postgis
  encoding: unicode
  ....

Will yield a system that is incompatible with database_validations, because the adapter name doesn't match, postgres.

Can you extend your supported adapters to also support postgres with the GIS extension?

Thanks!

@BrianHawley
Copy link

BrianHawley commented Sep 12, 2023

Hotpatch initializer to fix this issue:

# frozen_string_literal: true

begin
  DatabaseValidations::Adapters.factory(ActiveRecord::Base)
rescue DatabaseValidations::Errors::UnknownDatabase
  # Add support for the postgis adapter.
  DatabaseValidations::Adapters::PostgresqlAdapter.send(:remove_const, :ADAPTER)
  DatabaseValidations::Adapters::PostgresqlAdapter::ADAPTER = /\A(?:postgresql|postgis)\z/
end

This is based on a similar patch I made (today) to support the trilogy adapter. You don't have to make any other code changes because the adapter is checked with a case when statement.

FYI, here is the original hotpatch initializer for trilogy support:

# frozen_string_literal: true

begin
  DatabaseValidations::Adapters.factory(ActiveRecord::Base)
rescue DatabaseValidations::Errors::UnknownDatabase
  # Add support for the trilogy adapter.
  DatabaseValidations::Adapters::MysqlAdapter.send(:remove_const, :ADAPTER)
  DatabaseValidations::Adapters::MysqlAdapter::ADAPTER = /\A(?:mysql2|trilogy)\z/
end

If you're using an older Ruby version, you might want to freeze the regex. Newer Ruby versions freeze regex literals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants