ar-monocle 0.1.1 → 0.1.3
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 +4 -4
- data/Gemfile.lock +9 -9
- data/lib/monocle.rb +62 -51
- data/lib/monocle/configuration.rb +16 -0
- data/lib/monocle/railtie.rb +2 -2
- data/lib/monocle/version.rb +1 -1
- data/lib/monocle/view.rb +13 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 526a9406fbfc24cd93f3c599076c3bf891ec1239
|
4
|
+
data.tar.gz: 953fc1ec3bafa1c8c516ee3c2cb0c0e3a04be615
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 144cbbef782122cb73820116c47aa89bd32ae292ac3e82ea7ef89850d228d0aa61d4d2fbfbf86b2ad7bf81ecaa680eba1ec2d51d9b2f4561213595de918198d3
|
7
|
+
data.tar.gz: 2295282ecd7a50af58f8a4deae568168a68f900518c50e2afc6db37dc17cc9789e43f527da874f0ebe68f053a9f8132baaef7e221f9119be1ad386d706aeb754
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ar-monocle (0.1.
|
4
|
+
ar-monocle (0.1.2)
|
5
5
|
activerecord (>= 4, < 6)
|
6
6
|
activesupport (>= 4, < 6)
|
7
7
|
rake
|
@@ -9,13 +9,13 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activemodel (5.0.
|
13
|
-
activesupport (= 5.0.
|
14
|
-
activerecord (5.0.
|
15
|
-
activemodel (= 5.0.
|
16
|
-
activesupport (= 5.0.
|
12
|
+
activemodel (5.0.2)
|
13
|
+
activesupport (= 5.0.2)
|
14
|
+
activerecord (5.0.2)
|
15
|
+
activemodel (= 5.0.2)
|
16
|
+
activesupport (= 5.0.2)
|
17
17
|
arel (~> 7.0)
|
18
|
-
activesupport (5.0.
|
18
|
+
activesupport (5.0.2)
|
19
19
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
20
20
|
i18n (~> 0.7)
|
21
21
|
minitest (~> 5.1)
|
@@ -26,7 +26,7 @@ GEM
|
|
26
26
|
database_cleaner (1.5.3)
|
27
27
|
diff-lcs (1.3)
|
28
28
|
dotenv (2.2.0)
|
29
|
-
i18n (0.
|
29
|
+
i18n (0.8.1)
|
30
30
|
metaclass (0.0.4)
|
31
31
|
method_source (0.8.2)
|
32
32
|
minitest (5.10.1)
|
@@ -55,7 +55,7 @@ GEM
|
|
55
55
|
rspec-support (3.5.0)
|
56
56
|
slop (3.6.0)
|
57
57
|
thread_safe (0.3.6)
|
58
|
-
tzinfo (1.2.
|
58
|
+
tzinfo (1.2.3)
|
59
59
|
thread_safe (~> 0.1)
|
60
60
|
|
61
61
|
PLATFORMS
|
data/lib/monocle.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require "active_support/core_ext/module/delegation"
|
3
3
|
require 'active_record'
|
4
4
|
|
5
|
+
require 'monocle/configuration'
|
5
6
|
require 'monocle/railtie' if defined?(Rails)
|
6
7
|
|
7
8
|
require "monocle/version"
|
@@ -13,71 +14,81 @@ require "monocle/bump_command"
|
|
13
14
|
require "monocle/list_command"
|
14
15
|
|
15
16
|
module Monocle
|
16
|
-
def self.list
|
17
|
-
@list ||= ListCommand.new.call
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.drop(view_name)
|
21
|
-
fetch(view_name).drop
|
22
|
-
end
|
23
17
|
|
24
|
-
|
25
|
-
|
26
|
-
end
|
18
|
+
class << self
|
19
|
+
delegate :path_to_views, :logger, to: :configuration
|
27
20
|
|
28
|
-
|
29
|
-
|
30
|
-
|
21
|
+
def list
|
22
|
+
@list ||= ListCommand.new.call
|
23
|
+
end
|
31
24
|
|
32
|
-
|
33
|
-
|
34
|
-
list.each do |key, view|
|
35
|
-
logger.debug "Checking if #{key} is up to date..."
|
36
|
-
view.migrate
|
25
|
+
def drop(view_name)
|
26
|
+
fetch(view_name).drop
|
37
27
|
end
|
38
|
-
logger.info "All done!"
|
39
|
-
end
|
40
28
|
|
41
|
-
|
42
|
-
|
43
|
-
|
29
|
+
def create(view_name)
|
30
|
+
fetch(view_name).create
|
31
|
+
end
|
44
32
|
|
45
|
-
|
46
|
-
|
47
|
-
|
33
|
+
def versions
|
34
|
+
Migration.versions
|
35
|
+
end
|
48
36
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
Logger.new(STDOUT).tap do |logger|
|
55
|
-
logger.level = Logger::ERROR
|
37
|
+
def migrate
|
38
|
+
logger.info "Starting materialized views migrations..."
|
39
|
+
list.each do |key, view|
|
40
|
+
logger.debug "Checking if #{key} is up to date..."
|
41
|
+
view.migrate
|
56
42
|
end
|
43
|
+
logger.info "All done!"
|
57
44
|
end
|
58
|
-
end
|
59
45
|
|
60
|
-
|
61
|
-
|
62
|
-
@views_path ||= if defined?(Rails)
|
63
|
-
File.join Rails.root, "db/views"
|
64
|
-
else
|
65
|
-
File.join Monocle.root, "db/views"
|
46
|
+
def bump(view_name)
|
47
|
+
BumpCommand.new(fetch(view_name)).call
|
66
48
|
end
|
67
|
-
end
|
68
49
|
|
69
|
-
|
70
|
-
|
71
|
-
|
50
|
+
def refresh(view_name, concurrently: false)
|
51
|
+
fetch(view_name).refresh concurrently: concurrently
|
52
|
+
end
|
72
53
|
|
73
|
-
|
54
|
+
# Enables you to configure things in a block, i.e
|
55
|
+
# Monocle.configure do |config|
|
56
|
+
# config.logger = MyLogger.new
|
57
|
+
# config.path_to_views = "my/different/path/to/my/sql/files"
|
58
|
+
# end
|
59
|
+
def configure
|
60
|
+
yield configuration if block_given?
|
61
|
+
end
|
74
62
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
63
|
+
def views_path
|
64
|
+
File.join(root, path_to_views)
|
65
|
+
end
|
66
|
+
|
67
|
+
def root
|
68
|
+
# Get the absolute path of the project who is using us
|
69
|
+
File.expand_path(Dir.pwd)
|
70
|
+
end
|
71
|
+
|
72
|
+
def gem_root
|
73
|
+
# Get the absolute path of our gem root
|
74
|
+
File.expand_path(File.dirname(__dir__))
|
75
|
+
end
|
79
76
|
|
80
|
-
|
81
|
-
|
77
|
+
def fetch(view_name)
|
78
|
+
view_name = symbolize_name(view_name)
|
79
|
+
list.fetch(view_name)
|
80
|
+
end
|
81
|
+
|
82
|
+
protected
|
83
|
+
|
84
|
+
def configuration
|
85
|
+
@configuration ||= Configuration.new
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
def symbolize_name(name)
|
90
|
+
name.is_a?(String) ? name.to_sym : name
|
91
|
+
end
|
82
92
|
end
|
93
|
+
|
83
94
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Monocle
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :path_to_views, :logger
|
4
|
+
|
5
|
+
# Define a custom logger
|
6
|
+
def logger
|
7
|
+
@logger ||= (defined?(Rails) ? Rails.logger : Logger.new('monocle.log'))
|
8
|
+
end
|
9
|
+
|
10
|
+
# The relative path to where views are stored, relative to the root of the
|
11
|
+
# project
|
12
|
+
def path_to_views
|
13
|
+
@path_to_views ||= "db/views"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/monocle/railtie.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Monocle
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
rake_tasks do
|
4
|
-
load File.join(Monocle.
|
4
|
+
load File.join(Monocle.gem_root, "lib/tasks/monocle.rake")
|
5
5
|
end
|
6
6
|
|
7
7
|
generators do
|
8
|
-
Dir[File.join(Monocle.
|
8
|
+
Dir[File.join(Monocle.gem_root, "lib/monocle/generators/*.rb")].each { |f| require f }
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
data/lib/monocle/version.rb
CHANGED
data/lib/monocle/view.rb
CHANGED
@@ -40,6 +40,19 @@ module Monocle
|
|
40
40
|
Migration.find_or_create_by version: slug
|
41
41
|
dependants.each &:create
|
42
42
|
true
|
43
|
+
rescue ActiveRecord::StatementInvalid => e
|
44
|
+
# We may have another new view coming that this view depend on
|
45
|
+
# if the relation name is included on our list of views, we create
|
46
|
+
# that first and then retry
|
47
|
+
if e.message =~ /PG::UndefinedTable/ &&
|
48
|
+
e.message.scan(/relation \"(\w+)\" does not exist/) &&
|
49
|
+
list.keys.include?($1.to_sym)
|
50
|
+
warn "Can't create #{name} because it depends on #{$1}, creating that first..."
|
51
|
+
list.fetch($1.to_sym).create
|
52
|
+
retry
|
53
|
+
else
|
54
|
+
fail e
|
55
|
+
end
|
43
56
|
end
|
44
57
|
|
45
58
|
def migrate
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar-monocle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leonardo Bighetti
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -178,6 +178,7 @@ files:
|
|
178
178
|
- bin/setup
|
179
179
|
- lib/monocle.rb
|
180
180
|
- lib/monocle/bump_command.rb
|
181
|
+
- lib/monocle/configuration.rb
|
181
182
|
- lib/monocle/generators/install_generator.rb
|
182
183
|
- lib/monocle/generators/matview_generator.rb
|
183
184
|
- lib/monocle/generators/view_generator.rb
|