Refactor how credentials works to be a bit more agnostic#1135
Refactor how credentials works to be a bit more agnostic#1135
Conversation
… new placeholder idea Engine to support alternate engines. We can now start changing code for Cockroach specific cases. Ref #415
|
Looks good. Can't the engine be detected automatically?: def cockroachdb?
with_connection do |connection|
version = connection.scalar("SELECT version();").as(String)
version.starts_with?("CockroachDB") # <= or .starts_with?("PostgreSQL") etc
end
end |
|
I was thinking of such method being called once somewhere higher up the chain (or memoized) and used everywhere. You make a very good point on redshift, though. I guess there may be more cases like that that make the version string unreliable. Your current solution's better, I think. I guess once this is merged we can start to replace all the previous cockroachdb hacks? |
Yup! Now, I am open to alternate implementations, but I think it still needs to be at the DB instance level so in case you have your main DB, but maybe separate models that connect to say ClickHouse, or Redshift for pulling stats. This was just the first method that came to mind that seemed the most straight forward and easy. So if anyone has an idea, we can always mess with this a bit more. |

Ref #415
This PR starts the work to make Avram a little more agnostic. Supporting alternate DBs like MySQL, or SQLite would still present a very hefty challenge since there's not a lot of people that contribute to this library, and I only use postgres. However, we've already had a few issues where CockroachDB differs from postgres even though it's uses the postgres protocol. With this change, we can now at least do something like
A ton of things would need massive refactoring and thought before trying to support any non-postgres related DB like the
PG.connect_listenor usingPQ::Notification, etc.. I'll worry about those later.For now, the big benefit is
Avram::Credentialsis now just a thing wrapper aroundURIso we no longer need to handle complex building logic.