I have a Rails app (currently 6.1 but I can easily upgrade it if necessary) that connects to external MSSQL databases and provides an API (read-only) with the data.
I use these gems to help me access the databases:
gem 'activerecord-sqlserver-adapter', '6.1.2'
gem 'composite_primary_keys', '13.0.0'
gem 'tiny_tds', '2.1.5'
I have many of these MSSQL databases that have identical tables/views, but are connected to different data sources, and I use this one app to be able to create an API from these databases.
Right now, a quick setup hack I was able to do was to:
create a subdomain (ex db1.domain.com, db2.domain.com)
create multiple databases in my database.yml:
db1:
<<: *default
database: db2
db1:
<<: *default
database: db1
create environment configs for each db
spin up an app on the server catching the subdomain and setting RAILS_ENV to be db1 and db2
This works fine, but it's not dynamic! It was good for the first 2-3 times, but we are now over 20 databases, and I don't want each new database to have to be done manually continuously.
I would love for domain.com/db1 and domain.com/db2 to dynamically know that the database is db1 and db2 even though no code has been changed in the app and no new apps were spun up in the server.
I know Rails now supports multiple databases, but I could not figure it out with the MSSQL the last time I tried (right when it was released).
I'm going to take another deep dive into this, but wondering if anyone here has had any similar experiences or advice for me.
Any tips, tricks, or advice are super appreciated!
Thanks