scenic 1.5.1 → 1.5.2

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
  SHA256:
3
- metadata.gz: 4e48c4898ced79e149309b431569eff692ef95ff075a57ad0a02f2b80b59a262
4
- data.tar.gz: 7de8b684edffe599452d125aaed7f32111bfc4f99ef4b7e475ca0b2882c7c137
3
+ metadata.gz: 75afe5531011de8c35f2272af574763575bdb4d9f9650eeb2845a3f163b1e941
4
+ data.tar.gz: a7ded9f2177997aba8c3c424e04c2aed14f08a2f452d4ab74d2030d692fe1e7c
5
5
  SHA512:
6
- metadata.gz: 5a3f7c1e233cd63be18a94ac39c44f36baff1f1c1ba6cdcc71aa31063c52c2220b3321455a2e904366c157ed419d0a20454dccfdd22e66e42508584865f0aabe
7
- data.tar.gz: 0ee497506b13cdf2b64c49aea4b18fc351cf620b902acb962a8c9b5281c319b37b473f56ecfbcb873f4561e521780a54c6c6269d43ac841cfc4a3508213a61af
6
+ metadata.gz: f1d00648e7f6c73b76242d43b3d49456afbc531a3a562dd43525b1f45f0b440f8650f1d4fb9459780aba7e46e87b49d33b3f7b92693ae43f03d51ea1fee39a67
7
+ data.tar.gz: 7da8bfdf0cac0c7bea6a7e67f09a37767943d5e6f2608ffb478db0b2884a93bc76e06b2b0d8fcf52a7d95d7b10d154d3b7cd2065de022a44d669f61b88699cfa
data/.travis.yml CHANGED
@@ -18,21 +18,17 @@ notifications:
18
18
  - false
19
19
  sudo: false
20
20
  rvm:
21
- - 2.6.1
22
- - 2.5.3
21
+ - 2.7.0
23
22
  - 2.4.5
24
- - 2.3.8
25
23
  gemfile:
26
- - gemfiles/rails42.gemfile
27
- - gemfiles/rails50.gemfile
28
- - gemfiles/rails51.gemfile
29
24
  - gemfiles/rails52.gemfile
25
+ - gemfiles/rails60.gemfile
30
26
  - gemfiles/rails_edge.gemfile
31
27
  matrix:
32
28
  allow_failures:
33
29
  - gemfile: gemfiles/rails_edge.gemfile
34
30
  exclude:
35
- - rvm: 2.3.8
36
- gemfile: gemfiles/rails_edge.gemfile
31
+ - rvm: 2.4.5
32
+ gemfile: gemfiles/rails60.gemfile
37
33
  - rvm: 2.4.5
38
34
  gemfile: gemfiles/rails_edge.gemfile
data/Appraisals CHANGED
@@ -1,24 +1,14 @@
1
- appraise "rails42" do
2
- gem "activerecord", "~> 4.2.0"
3
- gem "railties", "~> 4.2.0"
4
- end
5
-
6
- appraise "rails50" do
7
- gem "activerecord", "~> 5.0.0"
8
- gem "railties", "~> 5.0.0"
9
- end
10
-
11
- appraise "rails51" do
12
- gem "activerecord", "~> 5.1.0"
13
- gem "railties", "~> 5.1.0"
14
- end
15
-
16
1
  appraise "rails52" do
17
2
  gem "activerecord", "~> 5.2.0"
18
3
  gem "railties", "~> 5.2.0"
19
4
  end
20
5
 
21
6
  if RUBY_VERSION >= "2.5.0"
7
+ appraise "rails60" do
8
+ gem "activerecord", "~> 6.0.0"
9
+ gem "railties", "~> 6.0.0"
10
+ end
11
+
22
12
  appraise "rails-edge" do
23
13
  gem "rails", git: "https://github.com/rails/rails"
24
14
  gem "arel", git: "https://github.com/rails/arel"
@@ -1,9 +1,22 @@
1
- # News
1
+ # Changelog
2
2
 
3
3
  The noteworthy changes for each Scenic version are included here. For a complete
4
- changelog, see the [CHANGELOG] for each version via the version links.
4
+ changelog, see the [commits] for each version via the version links.
5
5
 
6
- [CHANGELOG]: https://github.com/scenic-views/scenic/commits/master
6
+ [commits]: https://github.com/scenic-views/scenic/commits/master
7
+
8
+ ## [1.5.2] - February 6, 2019
9
+
10
+ ### Fixed
11
+
12
+ - The schema statement `create_view` is now reversible when passed a `version`
13
+ argument.
14
+ - Calling `refresh_materialized_view` with both `concurrently` and `cascade` set
15
+ to `true` now correctly cascades the concurrent refresh to dependent views.
16
+ - File generation and lookup now operates correctly for schema-qualified names
17
+ like `warehouse.archived_posts`.
18
+
19
+ [1.5.2]: https://github.com/scenic-views/scenic/compare/v1.5.1...v1.5.2
7
20
 
8
21
  ## [1.5.1] - February 10, 2019
9
22
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 4.2.0"
6
- gem "railties", "~> 4.2.0"
5
+ gem "activerecord", "~> 6.0.0"
6
+ gem "railties", "~> 6.0.0"
7
7
 
8
8
  gemspec path: "../"
@@ -73,6 +73,12 @@ module Scenic
73
73
 
74
74
  private
75
75
 
76
+ alias singular_name file_name
77
+
78
+ def file_name
79
+ super.tr(".", "_")
80
+ end
81
+
76
82
  def views_directory_path
77
83
  @views_directory_path ||= Rails.root.join("db", "views")
78
84
  end
@@ -93,10 +99,6 @@ module Scenic
93
99
  Scenic::Definition.new(plural_file_name, previous_version)
94
100
  end
95
101
 
96
- def plural_file_name
97
- @plural_file_name ||= file_name.pluralize.tr(".", "_")
98
- end
99
-
100
102
  def destroying?
101
103
  behavior == :revoke
102
104
  end
@@ -209,8 +209,9 @@ module Scenic
209
209
  # @return [void]
210
210
  def refresh_materialized_view(name, concurrently: false, cascade: false)
211
211
  raise_unless_materialized_views_supported
212
+
212
213
  if cascade
213
- refresh_dependencies_for(name)
214
+ refresh_dependencies_for(name, concurrently: concurrently)
214
215
  end
215
216
 
216
217
  if concurrently
@@ -242,11 +243,12 @@ module Scenic
242
243
  end
243
244
  end
244
245
 
245
- def refresh_dependencies_for(name)
246
+ def refresh_dependencies_for(name, concurrently: false)
246
247
  Scenic::Adapters::Postgres::RefreshDependencies.call(
247
248
  name,
248
249
  self,
249
250
  connection,
251
+ concurrently: concurrently,
250
252
  )
251
253
  end
252
254
  end
@@ -2,25 +2,29 @@ module Scenic
2
2
  module Adapters
3
3
  class Postgres
4
4
  class RefreshDependencies
5
- def self.call(name, adapter, connection)
6
- new(name, adapter, connection).call
5
+ def self.call(name, adapter, connection, concurrently: false)
6
+ new(name, adapter, connection, concurrently: concurrently).call
7
7
  end
8
8
 
9
- def initialize(name, adapter, connection)
9
+ def initialize(name, adapter, connection, concurrently:)
10
10
  @name = name
11
11
  @adapter = adapter
12
12
  @connection = connection
13
+ @concurrently = concurrently
13
14
  end
14
15
 
15
16
  def call
16
17
  dependencies.each do |dependency|
17
- adapter.refresh_materialized_view(dependency)
18
+ adapter.refresh_materialized_view(
19
+ dependency,
20
+ concurrently: concurrently,
21
+ )
18
22
  end
19
23
  end
20
24
 
21
25
  private
22
26
 
23
- attr_reader :name, :adapter, :connection
27
+ attr_reader :name, :adapter, :connection, :concurrently
24
28
 
25
29
  class DependencyParser
26
30
  def initialize(raw_dependencies, view_to_refresh)
@@ -20,7 +20,8 @@ module Scenic
20
20
  end
21
21
 
22
22
  def invert_create_view(args)
23
- [:drop_view, args]
23
+ drop_view_args = StatementArguments.new(args).remove_version.to_a
24
+ [:drop_view, drop_view_args]
24
25
  end
25
26
 
26
27
  def invert_drop_view(args)
@@ -22,8 +22,12 @@ module Scenic
22
22
  StatementArguments.new([view, options_for_revert])
23
23
  end
24
24
 
25
+ def remove_version
26
+ StatementArguments.new([view, options_without_version])
27
+ end
28
+
25
29
  def to_a
26
- @args.to_a
30
+ @args.to_a.dup.delete_if(&:empty?)
27
31
  end
28
32
 
29
33
  private
@@ -38,6 +42,10 @@ module Scenic
38
42
  revert_options.delete(:revert_to_version)
39
43
  end
40
44
  end
45
+
46
+ def options_without_version
47
+ options.except(:version)
48
+ end
41
49
  end
42
50
  end
43
51
  end
@@ -2,7 +2,7 @@ module Scenic
2
2
  class Configuration
3
3
  # The Scenic database adapter instance to use when executing SQL.
4
4
  #
5
- # Defualts to an instance of {Adapters::Postgres}
5
+ # Defaults to an instance of {Adapters::Postgres}
6
6
  # @return Scenic adapter
7
7
  attr_accessor :database
8
8
 
@@ -29,7 +29,7 @@ module Scenic
29
29
  private
30
30
 
31
31
  def filename
32
- "#{@name}_v#{version}.sql"
32
+ "#{@name.to_s.tr('.', '_')}_v#{version}.sql"
33
33
  end
34
34
  end
35
35
  end
@@ -1,3 +1,3 @@
1
1
  module Scenic
2
- VERSION = "1.5.1".freeze
2
+ VERSION = "1.5.2".freeze
3
3
  end
@@ -38,14 +38,20 @@ describe Scenic::Generators::ViewGenerator, :generator do
38
38
  end
39
39
 
40
40
  context "for views created in a schema other than 'public'" do
41
- it "creates view definition and migration files" do
42
- migration = file("db/migrate/create_non_public_searches.rb")
41
+ it "creates a view definition" do
43
42
  view_definition = file("db/views/non_public_searches_v01.sql")
44
43
 
45
44
  run_generator ["non_public.search"]
46
45
 
47
- expect(migration).to be_a_migration
48
46
  expect(view_definition).to exist
49
47
  end
48
+
49
+ it "creates a migration file" do
50
+ run_generator ["non_public.search"]
51
+
52
+ migration = migration_file("db/migrate/create_non_public_searches.rb")
53
+ expect(migration).to contain(/class CreateNonPublicSearches/)
54
+ expect(migration).to contain(/create_view "non_public.searches"/)
55
+ end
50
56
  end
51
57
  end
@@ -33,19 +33,24 @@ module Scenic
33
33
  )
34
34
 
35
35
  expect(adapter).to receive(:refresh_materialized_view)
36
- .with("public.first").ordered
36
+ .with("public.first", concurrently: true).ordered
37
37
  expect(adapter).to receive(:refresh_materialized_view)
38
- .with("public.second").ordered
38
+ .with("public.second", concurrently: true).ordered
39
39
  expect(adapter).to receive(:refresh_materialized_view)
40
- .with("public.third").ordered
40
+ .with("public.third", concurrently: true).ordered
41
41
  expect(adapter).to receive(:refresh_materialized_view)
42
- .with("public.fourth_1").ordered
42
+ .with("public.fourth_1", concurrently: true).ordered
43
43
  expect(adapter).to receive(:refresh_materialized_view)
44
- .with("public.x_fourth").ordered
44
+ .with("public.x_fourth", concurrently: true).ordered
45
45
  end
46
46
 
47
47
  it "refreshes in the right order when called without namespace" do
48
- described_class.call(:fourth, adapter, ActiveRecord::Base.connection)
48
+ described_class.call(
49
+ :fourth,
50
+ adapter,
51
+ ActiveRecord::Base.connection,
52
+ concurrently: true,
53
+ )
49
54
  end
50
55
 
51
56
  it "refreshes in the right order when called with namespace" do
@@ -53,6 +58,7 @@ module Scenic
53
58
  "public.fourth",
54
59
  adapter,
55
60
  ActiveRecord::Base.connection,
61
+ concurrently: true,
56
62
  )
57
63
  end
58
64
  end
@@ -119,8 +119,14 @@ module Scenic
119
119
  connectable = double("Connectable", connection: connection)
120
120
  adapter = Postgres.new(connectable)
121
121
  expect(Scenic::Adapters::Postgres::RefreshDependencies)
122
- .to receive(:call).with(:tests, adapter, connection)
123
- adapter.refresh_materialized_view(:tests, cascade: true)
122
+ .to receive(:call)
123
+ .with(:tests, adapter, connection, concurrently: true)
124
+
125
+ adapter.refresh_materialized_view(
126
+ :tests,
127
+ cascade: true,
128
+ concurrently: true,
129
+ )
124
130
  end
125
131
 
126
132
  context "refreshing concurrently" do
@@ -8,11 +8,25 @@ describe Scenic::CommandRecorder do
8
8
  expect(recorder.commands).to eq [[:create_view, [:greetings], nil]]
9
9
  end
10
10
 
11
- it "reverts to drop_view" do
11
+ it "reverts to drop_view when not passed a version" do
12
12
  recorder.revert { recorder.create_view :greetings }
13
13
 
14
14
  expect(recorder.commands).to eq [[:drop_view, [:greetings]]]
15
15
  end
16
+
17
+ it "reverts to drop_view when passed a version" do
18
+ recorder.revert { recorder.create_view :greetings, version: 2 }
19
+
20
+ expect(recorder.commands).to eq [[:drop_view, [:greetings]]]
21
+ end
22
+
23
+ it "reverts materialized views appropriately" do
24
+ recorder.revert { recorder.create_view :greetings, materialized: true }
25
+
26
+ expect(recorder.commands).to eq [
27
+ [:drop_view, [:greetings, materialized: true]],
28
+ ]
29
+ end
16
30
  end
17
31
 
18
32
  describe "#drop_view" do
@@ -29,6 +29,12 @@ module Scenic
29
29
 
30
30
  expect(definition.path).to eq expected
31
31
  end
32
+
33
+ it "handles schema qualified view names" do
34
+ definition = Definition.new("non_public.searches", 1)
35
+
36
+ expect(definition.path).to eq "db/views/non_public_searches_v01.sql"
37
+ end
32
38
  end
33
39
 
34
40
  describe "full_path" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scenic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Prior
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-02-11 00:00:00.000000000 Z
12
+ date: 2020-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: appraisal
@@ -195,11 +195,11 @@ files:
195
195
  - ".travis.yml"
196
196
  - ".yardopts"
197
197
  - Appraisals
198
+ - CHANGELOG.md
198
199
  - CODE_OF_CONDUCT.md
199
200
  - CONTRIBUTING.md
200
201
  - Gemfile
201
202
  - LICENSE.txt
202
- - NEWS.md
203
203
  - README.md
204
204
  - Rakefile
205
205
  - bin/appraisal
@@ -207,10 +207,8 @@ files:
207
207
  - bin/rspec
208
208
  - bin/setup
209
209
  - bin/yard
210
- - gemfiles/rails42.gemfile
211
- - gemfiles/rails50.gemfile
212
- - gemfiles/rails51.gemfile
213
210
  - gemfiles/rails52.gemfile
211
+ - gemfiles/rails60.gemfile
214
212
  - gemfiles/rails_edge.gemfile
215
213
  - lib/generators/scenic/generators.rb
216
214
  - lib/generators/scenic/materializable.rb
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 5.0.0"
6
- gem "railties", "~> 5.0.0"
7
-
8
- gemspec path: "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 5.1.0"
6
- gem "railties", "~> 5.1.0"
7
-
8
- gemspec path: "../"