viewy 0.1.1 → 0.1.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
  SHA1:
3
- metadata.gz: d0d346f0a7be5e2986dfc28c44ce149b6fc47f5d
4
- data.tar.gz: c771b0de1a80db6c793766f11a5ffb6ec32fc511
3
+ metadata.gz: 5eff5c5e346be1ca5ab408f4b37431d8af0b102a
4
+ data.tar.gz: 4699cfb5e13e4331e455f6e970afceb566050e30
5
5
  SHA512:
6
- metadata.gz: 778cd9146f3d4be1c9f8ed9954b3316cc67e0ef6ee8df7adcc234dbf4820a0a23774310c74d818b0f7e304b0c2189b5b23000248b4c319eb5ca5f999e29e2781
7
- data.tar.gz: 5d0a92306ab08af4e2725894f40fa5de6c3a032ff66931b3f700e15b7e17f0a8958bedf7002804723f81c42f92e53a8f0b61ed212e9fbb15d6de29db59cd2c91
6
+ metadata.gz: 763d4f573e981231058164708e19507e82e904093a7f095cde7aabf27e3dd335e381dba3a2d7e6701bc31ddf4d5362e0dedd10c59cb8bfe145ae0cc6d6e2401a
7
+ data.tar.gz: 673a0b105715622bc7a8966a777f7855073ce9d5a42daab3ca4780757a6ccec6636e64c9fd482c0a9b07361df2390c5f82e755cced92eeecb08c86cc2b44916e
@@ -72,12 +72,16 @@ class AddIndexRecreation < ActiveRecord::Migration
72
72
  FOREACH current_statement IN ARRAY create_statements LOOP
73
73
  EXECUTE current_statement;
74
74
  END LOOP;
75
- FOREACH current_index_statement IN ARRAY index_statements LOOP
76
- EXECUTE current_index_statement;
77
- END LOOP;
78
- FOREACH current_index_statement IN ARRAY current_index_statements LOOP
79
- EXECUTE current_index_statement;
80
- END LOOP;
75
+ IF index_statements IS NOT NULL THEN
76
+ FOREACH current_index_statement IN ARRAY index_statements LOOP
77
+ EXECUTE current_index_statement;
78
+ END LOOP;
79
+ END IF;
80
+ IF current_index_statements IS NOT NULL THEN
81
+ FOREACH current_index_statement IN ARRAY current_index_statements LOOP
82
+ EXECUTE current_index_statement;
83
+ END LOOP;
84
+ END IF;
81
85
  ALTER EVENT TRIGGER view_dependencies_update ENABLE ALWAYS;
82
86
  END;
83
87
  $$ LANGUAGE plpgsql;
@@ -42,7 +42,29 @@ module Viewy
42
42
  end
43
43
 
44
44
  private def refresh_single_view(view_name, concurrently:)
45
- connection.execute(refresh_sql(view_name, concurrently))
45
+ begin
46
+ connection.execute(refresh_sql(view_name, concurrently))
47
+ rescue ActiveRecord::StatementInvalid => ex
48
+ if attempt_non_concurrent_refresh?(ex, concurrently)
49
+ connection.execute(refresh_sql(view_name, false))
50
+ end
51
+ end
52
+ end
53
+
54
+ # @param ex [ActiveRecord::StatementInvalid] an exception raised during the view refresh
55
+ # @param concurrently [Boolean] whether or not the refresh that raised the exception was concurrent
56
+ #
57
+ # @raise [ActiveRecord::StatementInvalid] re-raised if the original exception is not a FeatureNotSupported exception
58
+ #
59
+ # @return [Boolean] true if the system should attempt to refresh the view non-concurrently after a concurrent
60
+ # refresh has failed. Since Postgres raises an error when an unpopulated view is refreshed concurrently, this
61
+ # allows the system to populated such views if needed
62
+ private def attempt_non_concurrent_refresh?(ex, concurrently)
63
+ if ex.original_exception.instance_of?(PG::FeatureNotSupported)
64
+ concurrently
65
+ else
66
+ raise ex
67
+ end
46
68
  end
47
69
 
48
70
  # @param name [String] the name of a materialized view
data/lib/viewy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Viewy
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: viewy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emerson Huitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-13 00:00:00.000000000 Z
11
+ date: 2016-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails