module Cell::SanityCheck

Public Class Methods

check_active_record_adapter!() click to toggle source
# File lib/cell/sanity_check.rb, line 5
    def self.check_active_record_adapter!
      pg_base_adapter = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
      whitelist = []
      adapter_name = ActiveRecord::Base.connection.adapter_name

      unless ActiveRecord::Base.connection.is_a?(pg_base_adapter) ||
             whitelist.include?(adapter_name)
        msg <<~EOD
          Cell uses PostgreSQL-specific features that cannot be represented with your adapter.  If
          your adapter is a PostgreSQL spin-off, please open a pull request.

          Whitelist: #{whitelist.inspect}
          ActiveRecord adapter: #{adapter_name}
        EOD
        fail msg
      end
    rescue ActiveRecord::NoDatabaseError
      # Not our problem
    end
check_dump_schemas!() click to toggle source
# File lib/cell/sanity_check.rb, line 39
    def self.check_dump_schemas!
      dump_schemas = Rails.application.config.active_record.dump_schemas
      unless dump_schemas.to_s.match(/\bcell_prototype\b/)
        msg = <<~EOD
          Cell stores tenant templates in a PostgreSQL schema called "cell_prototype".

          Rails will not dump this schema by default with `db:structure:dump` without explicitly
          setting `dump_schemas`.

          You can configure this by adding a line like the following in application.rb:

            Rails.application.config.active_record.dump_schemas = "public,cell_prototype"
        EOD
        fail msg
      end
    end
check_schema_format!() click to toggle source
# File lib/cell/sanity_check.rb, line 26
    def self.check_schema_format!
      if Rails.application.config.active_record.schema_format != :sql
        msg = <<~EOD
          Cell uses PostgreSQL-specific features that cannot be represented using a schema_format
          other than :sql.  You need a definititive structure.sql instead of a schema.rb.  You can
          configure this by adding the following line to your application.rb:

            Rails.application.config.active_record.schema_format = :sql
        EOD
        fail msg
      end
    end