Files
flagship/app/models/organization.rb

30 lines
582 B
Ruby

# 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
has_many :users, dependent: :destroy
has_many :projects, through: :users
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