Skip to content

Commit 7e2670b

Browse files
committed
Implement Premium Enterprise Sharding
1 parent 3c16de2 commit 7e2670b

File tree

150 files changed

+398
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+398
-36
lines changed

app/controllers/pwb/application_controller.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ class ApplicationController < ActionController::Base
99
# Themes allowed to be switched via ?theme= URL parameter
1010
ALLOWED_THEMES = %w[default brisbane bologna].freeze
1111

12+
around_action :switch_tenant_shard
13+
14+
def switch_tenant_shard
15+
# Ensure website is loaded to determine shard
16+
website = current_website
17+
shard = website&.database_shard || :default
18+
19+
# Use the shard for all PwbTenant models
20+
# Note: We use writing role for both reading/writing in this simple example
21+
# to avoid connection switching complexity during the demo
22+
PwbTenant::ApplicationRecord.connected_to(shard: shard, role: :writing) do
23+
yield
24+
end
25+
end
26+
1227
def set_theme_path
1328
theme_name = current_website&.theme_name
1429
if params[:theme].present?

app/models/ahoy/event.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# == Schema Information
44
#
55
# Table name: ahoy_events
6+
# Database name: primary
67
#
78
# id :bigint not null, primary key
89
# name :string not null

app/models/ahoy/visit.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# == Schema Information
44
#
55
# Table name: ahoy_visits
6+
# Database name: primary
67
#
78
# id :bigint not null, primary key
89
# browser :string

app/models/i18n/backend/active_record/translation.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# == Schema Information
22
#
33
# Table name: translations
4+
# Database name: primary
45
#
56
# id :integer not null, primary key
67
# interpolations :text

app/models/pwb/address.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# == Schema Information
22
#
33
# Table name: pwb_addresses
4+
# Database name: primary
45
#
56
# id :integer not null, primary key
67
# city :string

app/models/pwb/agency.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Pwb
99
# == Schema Information
1010
#
1111
# Table name: pwb_agencies
12+
# Database name: primary
1213
#
1314
# id :integer not null, primary key
1415
# analytics_id_type :integer
@@ -50,7 +51,6 @@ module Pwb
5051
#
5152
# index_pwb_agencies_on_website_id (website_id)
5253
#
53-
#
5454
class Agency < ApplicationRecord
5555
self.table_name = 'pwb_agencies'
5656

app/models/pwb/auth_audit_log.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module Pwb
1818
# == Schema Information
1919
#
2020
# Table name: pwb_auth_audit_logs
21+
# Database name: primary
2122
#
2223
# id :bigint not null, primary key
2324
# email :string
@@ -49,7 +50,6 @@ module Pwb
4950
# fk_rails_... (user_id => pwb_users.id)
5051
# fk_rails_... (website_id => pwb_websites.id)
5152
#
52-
#
5353
class AuthAuditLog < ApplicationRecord
5454
self.table_name = 'pwb_auth_audit_logs'
5555

app/models/pwb/authorization.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# == Schema Information
22
#
33
# Table name: pwb_authorizations
4+
# Database name: primary
45
#
56
# id :bigint not null, primary key
67
# provider :string

app/models/pwb/contact.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Pwb
99
# == Schema Information
1010
#
1111
# Table name: pwb_contacts
12+
# Database name: primary
1213
#
1314
# id :bigint not null, primary key
1415
# details :json
@@ -52,7 +53,6 @@ module Pwb
5253
#
5354
# fk_rails_... (website_id => pwb_websites.id)
5455
#
55-
#
5656
class Contact < ApplicationRecord
5757
self.table_name = 'pwb_contacts'
5858

app/models/pwb/content.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# == Schema Information
44
#
55
# Table name: pwb_contents
6+
# Database name: primary
67
#
78
# id :integer not null, primary key
89
# input_type :string

0 commit comments

Comments
 (0)