{"id":13819675,"url":"https://github.com/discourse/rails_multisite","last_synced_at":"2025-10-11T10:38:29.510Z","repository":{"id":2071921,"uuid":"44082506","full_name":"discourse/rails_multisite","owner":"discourse","description":"Multi tenancy for Rails applications","archived":false,"fork":false,"pushed_at":"2024-08-13T10:20:50.000Z","size":144,"stargazers_count":269,"open_issues_count":0,"forks_count":18,"subscribers_count":25,"default_branch":"main","last_synced_at":"2025-05-26T04:15:15.472Z","etag":null,"topics":["rubygem"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/discourse.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-12T03:39:28.000Z","updated_at":"2025-05-15T04:58:25.000Z","dependencies_parsed_at":"2024-11-07T12:22:42.729Z","dependency_job_id":"ad502109-7b80-4755-8f44-727c709ba9ec","html_url":"https://github.com/discourse/rails_multisite","commit_stats":{"total_commits":127,"total_committers":12,"mean_commits":"10.583333333333334","dds":0.5748031496062992,"last_synced_commit":"c595bc2617b219163242b64b0df448a9edb5018b"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/discourse/rails_multisite","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discourse%2Frails_multisite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discourse%2Frails_multisite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discourse%2Frails_multisite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discourse%2Frails_multisite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/discourse","download_url":"https://codeload.github.com/discourse/rails_multisite/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discourse%2Frails_multisite/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006853,"owners_count":26084207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rubygem"],"created_at":"2024-08-04T08:00:51.553Z","updated_at":"2025-10-11T10:38:29.493Z","avatar_url":"https://github.com/discourse.png","language":"Ruby","readme":"# Rails Multisite\n\nThis gem provides multi-db support for Rails applications.\n\nUsing its middleware you can partition your app so each hostname has its own db.\n\nIt provides a series of helper for working with multiple database, and some additional rails tasks for working with them.\n\nIt was extracted from Discourse. https://discourse.org\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'rails_multisite'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install rails_multisite\n\n## Usage\n\nConfiguration requires a file called: `config/multisite.yml` that specifies connection specs for all dbs.\n\n```\nmlp:\n  adapter: postgresql\n  database: discourse_mlp\n  username: discourse_mlp\n  password: applejack\n  host: dbhost\n  pool: 5\n  timeout: 5000\n  host_names:\n    - discourse.equestria.com\n    - discourse.equestria.internal\n\ndrwho:\n  adapter: postgresql\n  database: discourse_who\n  username: discourse_who\n  password: \"Up the time stream without a TARDIS\"\n  host: dbhost\n  pool: 5\n  timeout: 5000\n  host_names:\n    - discuss.tardis.gallifrey\n```\n\n\n### Execute a query on each connection\n\n```\nRailsMultisite::ConnectionManagement.each_connection do |db|\n  # run query in context of db\n  # eg: User.find(1)\nend\n```\n\n```\nRailsMultisite::ConnectionManagement.each_connection(threads: 5) do |db|\n  # run query in context of db, will do so in a thread pool of 5 threads\n  # if any query fails an exception will be raised\n  # eg: User.find(1)\nend\n```\n\n### Usage with Rails\n\n#### `RAILS_DB` Environment Variable\n\nWhen working with a Rails application, you can specify the DB that you'll like to work with by specifying the `RAILS_DB` ENV variable.\n\n```\n# config/multisite.yml\n\ndb_one:\n  adapter: ...\n  database: some_database_1\n\ndb_two:\n  adapater: ...\n  database: some_database_2\n```\n\nTo get a Rails console that is connected to `some_database_1` database:\n\n```\nRAILS_DB=db_one rails console\n```\n\n### CDN origin support\n\nTo avoid needing to configure many origins you can consider using `RailsMultisite::ConnectionManagement.asset_hostnames`\n\nWhen configured, requests to `asset_hostname`?__ws=another.host.name will be re-routed to the correct site. Cookies will\nbe stripped on all incoming requests.\n\nExample:\n\n- Multisite serves `sub.example.com` and `assets.example.com`\n- `RailsMultisite::ConnectionManagement.asset_hostnames = ['assets.example.com']`\n- Requests to `https://assets.example.com/route/?__ws=sub.example.com` will be routed to the `sub.example.com`\n\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Added some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","funding_links":[],"categories":["Happy Exploring 🤘","Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiscourse%2Frails_multisite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiscourse%2Frails_multisite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiscourse%2Frails_multisite/lists"}