File: load_schema.rb

package info (click to toggle)
ruby-combustion 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 332 kB
  • sloc: ruby: 628; makefile: 9; sh: 6
file content (38 lines) | stat: -rw-r--r-- 682 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

class Combustion::Database::LoadSchema
  UnknownSchemaFormat = Class.new StandardError

  def self.call
    new.call
  end

  def call
    ActiveRecord::Schema.verbose = false

    case schema_format
    when :ruby
      load_ruby_schema
    when :sql
      load_sql_schema
    else
      raise UnknownSchemaFormat, "Unknown schema format: #{schema_format}"
    end
  end

  private

  def load_ruby_schema
    load Rails.root.join("db", "schema.rb")
  end

  def load_sql_schema
    ActiveRecord::Base.connection.execute(
      File.read(Rails.root.join("db", "structure.sql"))
    )
  end

  def schema_format
    Combustion.schema_format
  end
end