create org model and schema manager
This commit is contained in:
27
app/models/organization.rb
Normal file
27
app/models/organization.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Organization < ApplicationRecord
|
||||
validates :name, presence: true
|
||||
validates :subdomain, presence: true, uniqueness: true
|
||||
|
||||
after_create :create_schema
|
||||
before_destroy :drop_schema
|
||||
|
||||
def schema_name
|
||||
"org_#{id.to_s.gsub('-', '_')}"
|
||||
end
|
||||
|
||||
def with_schema(&block)
|
||||
SchemaManager.with_schema(id, &block)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_schema
|
||||
SchemaManager.create_schema(id)
|
||||
end
|
||||
|
||||
def drop_schema
|
||||
SchemaManager.drop_schema(id)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user