spectacles 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93b01de9ec07bd98a69b60b3c1b15ae85a8e3b12
4
- data.tar.gz: d25a236871d3d35208e157419b69f25f935a1437
3
+ metadata.gz: e28478c01f62ccd9e9d3fc441caa9cd3883192b1
4
+ data.tar.gz: 329001b8c26885deb34289446cb53d955428ddcc
5
5
  SHA512:
6
- metadata.gz: 315b5606b2b1fb645b81846c4e3a49e8a018b9cfef29593094272636e7a31667e6a45121bc970952acbbd3c1f28197a05ab49dfebc166c3492cff2502b5a8401
7
- data.tar.gz: aef7db4bcfdd525337c5744f1d45962eff3edd691cd281157ddc87e432f03adffcc420a61a585732b776aa79f5053a13fb2b007a8b681bf56f872882803ec1e4
6
+ metadata.gz: ba3efd56888624a60ad098238ef8c3cedcf78bec42f1405e97ffd2a02ae014a4a84888face0cb7c3ef1a547c8cd995ae5bc16dec31e1b0ea159113b327b43a6d
7
+ data.tar.gz: daec41fa930df8b7686b66d6125aca194d6e4c0139b65d3dd2f6761438e5933b2a64f1448cab8775e45fb17fa6cbf33453cf3df12d0a83e83a09da4ddb8b1595
@@ -6,6 +6,7 @@ require 'spectacles/view'
6
6
  require 'spectacles/materialized_view'
7
7
  require 'spectacles/version'
8
8
  require 'spectacles/configuration'
9
+ require 'spectacles/abstract_adapter_override'
9
10
 
10
11
  require 'spectacles/railtie' if defined?(Rails)
11
12
 
@@ -23,21 +24,12 @@ module Spectacles
23
24
  end
24
25
  end
25
26
 
26
- ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do
27
- alias_method(:_spectacles_original_inherited, :inherited) if method_defined?(:inherited)
28
-
29
- def self.inherited(klass)
30
- ::Spectacles::load_adapters
31
- _spectacles_orig_inherited if method_defined?(:_spectacles_original_inherited)
32
- end
33
- end
34
-
35
27
  ActiveRecord::SchemaDumper.class_eval do
36
28
  alias_method(:_spectacles_orig_trailer, :trailer)
37
29
 
38
30
  def trailer(stream)
39
31
  ::Spectacles::SchemaDumper.dump_views(stream, @connection)
40
- ::Spectacles::SchemaDumper.dump_materialized_views(stream, @connection)
32
+ ::Spectacles::SchemaDumper.dump_materialized_views(self, stream, @connection)
41
33
  _spectacles_orig_trailer(stream)
42
34
  end
43
35
  end
@@ -0,0 +1,10 @@
1
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do
2
+ class << self
3
+ alias_method(:_spectacles_orig_inherited, :inherited) if method_defined?(:inherited)
4
+
5
+ def inherited(_subclass)
6
+ ::Spectacles::load_adapters
7
+ _spectacles_orig_inherited(_subclass) if methods.include?(:_spectacles_orig_inherited)
8
+ end
9
+ end
10
+ end
@@ -8,11 +8,12 @@ module Spectacles
8
8
  end
9
9
  end
10
10
 
11
- def self.dump_materialized_views(stream, connection)
11
+ def self.dump_materialized_views(dumper, stream, connection)
12
12
  unless (Spectacles.config.enable_schema_dump == false)
13
13
  if connection.supports_materialized_views?
14
14
  connection.materialized_views.sort.each do |view|
15
15
  dump_materialized_view(stream, connection, view)
16
+ dumper.send(:indexes, view, stream)
16
17
  end
17
18
  end
18
19
  end
@@ -7,10 +7,12 @@ module Spectacles
7
7
 
8
8
  def views(name = nil) #:nodoc:
9
9
  q = <<-SQL
10
- SELECT table_name, table_type
11
- FROM information_schema.tables
12
- WHERE table_schema = ANY(current_schemas(false))
13
- AND table_type = 'VIEW'
10
+ SELECT t.table_name, t.table_type
11
+ FROM information_schema.tables AS t
12
+ INNER JOIN pg_class AS c ON c.relname = t.table_name
13
+ WHERE t.table_schema = ANY(current_schemas(false))
14
+ AND t.table_type = 'VIEW'
15
+ AND pg_catalog.pg_get_userbyid(c.relowner) = #{quote(database_username)}
14
16
  SQL
15
17
 
16
18
  execute(q, name).map { |row| row['table_name'] }
@@ -145,6 +147,10 @@ module Spectacles
145
147
  hash
146
148
  end
147
149
  end
150
+
151
+ def database_username
152
+ @config[:username]
153
+ end
148
154
  end
149
155
  end
150
156
  end
@@ -1,3 +1,3 @@
1
1
  module Spectacles
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe "loading an adapter" do
4
+ it "calls the original AR::CA::AbstractAdapter.inherited method" do
5
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do
6
+ def self.inherited(subclass)
7
+ @_spectacles_inherited_called = true
8
+ end
9
+ end
10
+ load File.join(__dir__, '../../lib/spectacles/abstract_adapter_override.rb')
11
+ Class.new(ActiveRecord::ConnectionAdapters::AbstractAdapter)
12
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.instance_variable_get("@_spectacles_inherited_called").must_equal true
13
+ end
14
+ end
@@ -23,6 +23,8 @@ shared_examples_for "an adapter" do |adapter|
23
23
  products JOIN users ON users.id = products.user_id"
24
24
  end
25
25
 
26
+ ActiveRecord::Base.connection.add_index :materialized_product_users, :product_name
27
+
26
28
  ActiveRecord::Base.connection.create_materialized_view(:empty_materialized_product_users, storage: { fillfactor: 50 }, data: false, force: true) do
27
29
  "SELECT name AS product_name, first_name AS username FROM
28
30
  products JOIN users ON users.id = products.user_id"
@@ -43,6 +45,12 @@ shared_examples_for "an adapter" do |adapter|
43
45
  stream.string.must_match(/create_materialized_view/)
44
46
  end
45
47
 
48
+ it 'should return add_index in dump stream' do
49
+ stream = StringIO.new
50
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
51
+ stream.string.must_match(/add_index/)
52
+ end
53
+
46
54
  it "should include options for create_materialized_view" do
47
55
  stream = StringIO.new
48
56
  ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectacles
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Hutchison, Brandon Dewitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-29 00:00:00.000000000 Z
11
+ date: 2016-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -80,6 +80,7 @@ files:
80
80
  - Rakefile
81
81
  - Readme.rdoc
82
82
  - lib/spectacles.rb
83
+ - lib/spectacles/abstract_adapter_override.rb
83
84
  - lib/spectacles/configuration.rb
84
85
  - lib/spectacles/materialized_view.rb
85
86
  - lib/spectacles/railtie.rb
@@ -99,6 +100,7 @@ files:
99
100
  - specs/adapters/postgresql_adapter_spec.rb
100
101
  - specs/adapters/sqlite3_adapter_spec.rb
101
102
  - specs/spec_helper.rb
103
+ - specs/spectacles/abstract_adapter_override_spec.rb
102
104
  - specs/spectacles/schema_statements/abstract_adapter_spec.rb
103
105
  - specs/spectacles/view_spec.rb
104
106
  - specs/support/minitest_matchers.rb
@@ -126,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
128
  version: '0'
127
129
  requirements: []
128
130
  rubyforge_project:
129
- rubygems_version: 2.4.8
131
+ rubygems_version: 2.5.1
130
132
  signing_key:
131
133
  specification_version: 4
132
134
  summary: Spectacles (derived from RailsSQLViews) adds database view functionality