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
# 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
end

.check_dump_schemas!Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cell/sanity_check.rb', line 37

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 properly 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



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cell/sanity_check.rb', line 24

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

.sanity_check!Object



54
55
56
57
58
59
60
# File 'lib/cell/sanity_check.rb', line 54

def self.sanity_check!
  ActiveSupport.on_load(:active_record) do
    Cell::SanityCheck.check_active_record_adapter!
    Cell::SanityCheck.check_schema_format!
    Cell::SanityCheck.check_dump_schemas!
  end
end