Module: Cell::SanityCheck

Defined in:
lib/cell/sanity_check.rb

Class Method Summary collapse

Class Method Details

.check_active_record_adapter!Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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!Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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!Object



26
27
28
29
30
31
32
33
34
35
36
37
# 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