Single database for multiple shops

Use ActsAsTenant as Multi-tenancy for shops

See below files:
- app/controllers/concern/multi_tenancy.rb
- app/models/application_record.rb
- app/models/shop.rb

An initializer can be created to control option in ActsAsTenant.
config/initializers/acts_as_tenant.rb
require 'acts_as_tenant/sidekiq'
ActsAsTenant.configure do |config|
  config.require_tenant = false # true
end

more details: https://github.com/ErwinM/acts_as_tenant
This commit is contained in:
Thein Lin Kyaw
2019-12-02 17:19:28 +06:30
parent 5d10d4b6a1
commit 937f40e7c1
78 changed files with 215 additions and 173 deletions

View File

@@ -20,11 +20,11 @@ class CommissionerImageUploader < CarrierWave::Uploader::Base
end
def filename
if Shop.first.shop_code.nil?
"#{original_filename}" if original_filename.present?
if Shop.current_shop.shop_code.nil?
"#{original_filename}" if original_filename.present?
else
"#{Shop.first.shop_code}_#{original_filename}" if original_filename.present?
end
"#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present?
end
end
# def cache_dir
@@ -62,6 +62,6 @@ class CommissionerImageUploader < CarrierWave::Uploader::Base
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
# end
end
end

View File

@@ -20,11 +20,11 @@ class CustomerImageUploader < CarrierWave::Uploader::Base
end
def filename
if Shop.first.shop_code.nil?
"#{original_filename}" if original_filename.present?
if Shop.current_shop.shop_code.nil?
"#{original_filename}" if original_filename.present?
else
"#{Shop.first.shop_code}_#{original_filename}" if original_filename.present?
end
"#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present?
end
end
# def cache_dir
@@ -62,6 +62,6 @@ class CustomerImageUploader < CarrierWave::Uploader::Base
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
# end
end
end

View File

@@ -20,11 +20,11 @@ class EmployeeImageUploader < CarrierWave::Uploader::Base
end
def filename
if Shop.first.shop_code.nil?
"#{original_filename}" if original_filename.present?
if Shop.current_shop.shop_code.nil?
"#{original_filename}" if original_filename.present?
else
"#{Shop.first.shop_code}_#{original_filename}" if original_filename.present?
end
"#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present?
end
end
# def cache_dir
@@ -62,6 +62,6 @@ class EmployeeImageUploader < CarrierWave::Uploader::Base
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
# end
end
end

View File

@@ -15,16 +15,16 @@ class MenuItemImageUploader < CarrierWave::Uploader::Base
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"image/menu_images/#{Shop.first.shop_code}"
"image/menu_images/#{Shop.current_shop.shop_code}"
# "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def filename
if Shop.first.shop_code.nil?
"#{original_filename}" if original_filename.present?
if Shop.current_shop.shop_code.nil?
"#{original_filename}" if original_filename.present?
else
"#{Shop.first.shop_code}_#{original_filename}" if original_filename.present?
end
"#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present?
end
end
# def cache_dir
@@ -42,7 +42,7 @@ class MenuItemImageUploader < CarrierWave::Uploader::Base
# Process files as they are uploaded:
# process scale: [200, 300]
process :resize_to_fit => [400, 250]#[200, 150]
#
# def scale(width, height)
# # do something

View File

@@ -20,11 +20,11 @@ class ProductImageUploader < CarrierWave::Uploader::Base
end
def filename
if Shop.first.shop_code.nil?
"#{original_filename}" if original_filename.present?
if Shop.current_shop.shop_code.nil?
"#{original_filename}" if original_filename.present?
else
"#{Shop.first.shop_code}_#{original_filename}" if original_filename.present?
end
"#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present?
end
end
# def cache_dir

View File

@@ -20,11 +20,11 @@ class ShopImageUploader < CarrierWave::Uploader::Base
end
def filename
if Shop.first.shop_code.nil?
"#{original_filename}" if original_filename.present?
if Shop.current_shop.shop_code.nil?
"#{original_filename}" if original_filename.present?
else
"#{Shop.first.shop_code}_#{original_filename}" if original_filename.present?
end
"#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present?
end
end
# def cache_dir
@@ -62,6 +62,6 @@ class ShopImageUploader < CarrierWave::Uploader::Base
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
# end
end
end