create org model and schema manager

This commit is contained in:
2025-06-11 18:23:16 +02:00
parent 16b27a0d1c
commit 8be82f5c49
7 changed files with 144 additions and 0 deletions

View 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