penthouse 0.12.2 → 0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8c80eabcd8683ce926c3352a4c93d54f045eeb5
4
- data.tar.gz: 80b98c6090bcab5595fa65417d79bfaa8ab5a5de
3
+ metadata.gz: ffc67c3cad093e9b85e263bf9da478a4ca754111
4
+ data.tar.gz: 4b4161ccc5d1013ec0edb784a51579a32084096b
5
5
  SHA512:
6
- metadata.gz: 0165d7ce88345e0d096cddff925bc7d44618212f083b5e749af59b736326f2a6ee9f93420f735908a5b4b22f88452790a25e9b6b68f32031376a3b703bf4750e
7
- data.tar.gz: b748fe21135a04cfd3d8e49e7a041ada4f4a9caca1a3fca2aa4a73f6413709099645cea81e0d6a4d0d6cd4a0863fca3859c6056f25697b88f4606fc078873454
6
+ metadata.gz: 2e905c8ae73db898fa693bba19a5583276524e885eabb41b7fab59c8ce44beed5fce83711423d73456e867abd9383f34a17cdbd9eec6468d16a786fe0990d56d
7
+ data.tar.gz: f74210fbf84efdc2e2de0854eddb3f0d042d6b4a7307768a86a4c69ccd29e75c0691d27d0d812313e76facb9eea65c8f078878879e7d509b7432a03afdeb0f68
@@ -17,16 +17,60 @@ module Penthouse
17
17
  if File.exist?(db_schema_file)
18
18
  # run the migrations within this schema
19
19
  call do
20
- # don't output all the log messages
21
- ActiveRecord::Schema.verbose = false
22
- # run the schema file to migrate this tenant
23
- load(db_schema_file)
20
+ read_schema(db_schema_file)
24
21
  end
25
22
  else
26
23
  raise ArgumentError, "#{db_schema_file} does not exist"
27
24
  end
28
25
  end
29
26
 
27
+ private
28
+
29
+ def read_schema(db_schema_file)
30
+ case db_schema_file.extname
31
+ when '.rb'
32
+ load_ruby_schema(db_schema_file)
33
+ when '.sql'
34
+ load_sql_schema(db_schema_file)
35
+ else
36
+ raise ArgumentError, "Unrecognized schema file extension"
37
+ end
38
+ end
39
+
40
+ def load_ruby_schema(db_schema_file)
41
+ # don't output all the log messages
42
+ ActiveRecord::Schema.verbose = false
43
+ # run the schema file to migrate this tenant
44
+ load(db_schema_file)
45
+ end
46
+
47
+ def load_sql_schema(db_schema_file)
48
+ sql = process_schema_file(db_schema_file)
49
+
50
+ ActiveRecord::Base.transaction do
51
+ with_limited_logging { ActiveRecord::Base.connection.execute(sql) }
52
+ end
53
+ end
54
+
55
+ def with_limited_logging
56
+ temp_logger = Logger.new(STDOUT).tap { |l| l.level = Logger::ERROR }
57
+ current_logger = ActiveRecord::Base.logger
58
+
59
+ ActiveRecord::Base.logger = temp_logger
60
+ yield
61
+ ActiveRecord::Base.logger = current_logger
62
+ end
63
+
64
+ def process_schema_file(db_schema_file)
65
+ sql = File.read(db_schema_file)
66
+ sanitize_sql(sql)
67
+ end
68
+
69
+ def sanitize_sql(sql)
70
+ sql
71
+ .gsub(/SET search_path.*;/, '')
72
+ .gsub(/CREATE SCHEMA/, 'CREATE SCHEMA IF NOT EXISTS')
73
+ end
30
74
  end
31
75
  end
32
76
  end
@@ -1,3 +1,3 @@
1
1
  module Penthouse
2
- VERSION = "0.12.2"
2
+ VERSION = "0.13"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: penthouse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: '0.13'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Townsend
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-29 00:00:00.000000000 Z
11
+ date: 2018-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler