scenic 1.6.0 → 1.7.0

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
  SHA256:
3
- metadata.gz: 23461e20bd94ffe9d2466098b04141ef8b8256d83f6c05cf5c5d9f26cca08231
4
- data.tar.gz: 6c331ddfc7c4d658b342367e2f2fcf703bf2b376314c32520d55afdbc05e936a
3
+ metadata.gz: b378292bd7d642dcd235d01f5a31d94c74065b798ab469a9c091f68e936f4d9c
4
+ data.tar.gz: b97f6e156685d4c03761543d5748f1381447c94cfcc42f7d6ddb8714e16791d0
5
5
  SHA512:
6
- metadata.gz: 23e1ab6998fb898eebdc91691684bffc694fe51001ada435593cb9e6a3857074e13e6d1ba90333acf3a76069f2e687c129595389ce60ac7790bbb82cdfdd68c2
7
- data.tar.gz: 2d91d5a48e68ef856ea9ffb14c3abb503fcaa1c588e17f55775ef32d2ae5f4f2862fd68aa53a99b2c666a0a81d88cba026fa21cdf2f4cc5b5e8a3f8062eb4779
6
+ metadata.gz: 4ffb0c73e52da5122a8ce3092b7f280d1a1dcaac9ca03a5f8ea63fe361d1b011d3c71f54706ff17d8ee1768fbdc1ba32c38bfebbcda320271e0b751eaea340f3
7
+ data.tar.gz: 846d53ffe8c0d0209ab6517c47e0447ee3b40a81e5f55f845f16a1b3f697cebd44ad38550a5fe8d10016ab19b3c1197f36ea9f3f5f7f42395a1431790684e0c1
@@ -14,7 +14,7 @@ jobs:
14
14
  fail-fast: false
15
15
  matrix:
16
16
  ruby: ["2.7", "3.0", "3.1"]
17
- rails: ["6.1", "7.0", "master"]
17
+ rails: ["6.1", "7.0"]
18
18
  continue-on-error: [false]
19
19
 
20
20
  runs-on: ubuntu-latest
data/CHANGELOG.md CHANGED
@@ -5,21 +5,29 @@ changelog, see the [commits] for each version via the version links.
5
5
 
6
6
  [commits]: https://github.com/scenic-views/scenic/commits/master
7
7
 
8
- ## [1.6.0] - February 13, 2021
8
+ ## [1.7.0] - December 8, 2022
9
9
 
10
- ### Fixed
10
+ [1.7.0]: https://github.com/scenic-views/scenic/compare/v1.6.0...v1.7.0
11
+
12
+ ### Added
11
13
 
12
- * Exclude pg_stat_statements_info (#349) 76bface
14
+ * Added the `--replace` CLI flag to generate a migration that uses the
15
+ `replace_view` schema statement - *Dan Hixon*
13
16
 
14
- *Caleb Hearth*
17
+ ### Fixed
18
+
19
+ * Fixed deprecation notice from newer versions of ERB when using scenic
20
+ generators - *Ali Ismayilov*
15
21
 
16
- * Fix serialization of views with backslashes c625d1b
22
+ ## [1.6.0] - February 13, 2022
17
23
 
18
- *Ben Sheldon*
24
+ [1.6.0]: https://github.com/scenic-views/scenic/compare/v1.5.5...v1.6.0
19
25
 
20
- * Handle ActiveRecord table name prefix and suffix b1544dc
26
+ ### Fixed
21
27
 
22
- *Derek Prior*
28
+ * Exclude pg_stat_statements_info (#349) 76bface - *Caleb Hearth*
29
+ * Fix serialization of views with backslashes c625d1b - *Ben Sheldon*
30
+ * Handle ActiveRecord table name prefix and suffix b1544dc - *Derek Prior*
23
31
 
24
32
  ## [1.5.5] - December 15, 2021
25
33
 
data/README.md CHANGED
@@ -92,30 +92,19 @@ a new version of it.
92
92
  This is not desirable when you have complicated hierarchies of views, especially
93
93
  when some of those views may be materialized and take a long time to recreate.
94
94
 
95
- You can use `replace_view` to generate a CREATE OR REPLACE VIEW SQL statement.
96
-
97
- See Postgres documentation on how this works:
98
- http://www.postgresql.org/docs/current/static/sql-createview.html
99
-
100
- To start replacing a view run the generator like for a regular change:
95
+ You can use `replace_view` to generate a CREATE OR REPLACE VIEW SQL statement
96
+ instead by adding the `--replace` option to the generate command:
101
97
 
102
98
  ```sh
103
- $ rails generate scenic:view search_results
99
+ $ rails generate scenic:view search_results --replace
104
100
  create db/views/search_results_v02.sql
105
101
  create db/migrate/[TIMESTAMP]_update_search_results_to_version_2.rb
106
102
  ```
107
103
 
108
- Now, edit the migration. It should look something like:
109
-
110
- ```ruby
111
- class UpdateSearchResultsToVersion2 < ActiveRecord::Migration
112
- def change
113
- update_view :search_results, version: 2, revert_to_version: 1
114
- end
115
- end
116
- ```
104
+ See Postgres documentation on how this works:
105
+ http://www.postgresql.org/docs/current/static/sql-createview.html
117
106
 
118
- Update it to use replace view:
107
+ The migration will look something like this:
119
108
 
120
109
  ```ruby
121
110
  class UpdateSearchResultsToVersion2 < ActiveRecord::Migration
@@ -125,7 +114,7 @@ class UpdateSearchResultsToVersion2 < ActiveRecord::Migration
125
114
  end
126
115
  ```
127
116
 
128
- Now you can run the migration like normal.
117
+ You can run the migration and the view will be replaced instead.
129
118
 
130
119
  ## Can I use this view to back a model?
131
120
 
@@ -252,16 +241,21 @@ accommodate adapter gems.
252
241
  We are aware of the following existing adapter libraries for Scenic which may
253
242
  meet your needs:
254
243
 
255
- * [scenic_sqlite_adapter](https://github.com/pdebelak/scenic_sqlite_adapter)
256
- * [scenic-mysql_adapter](https://github.com/EmpaticoOrg/scenic-mysql_adapter)
257
- * [scenic-sqlserver-adapter](https://github.com/ClickMechanic/scenic_sqlserver_adapter)
258
- * [scenic-oracle_adapter](https://github.com/cdinger/scenic-oracle_adapter)
244
+ * [`scenic_sqlite_adapter`](<https://github.com/pdebelak/scenic_sqlite_adapter>)
245
+ * [`scenic-mysql_adapter`](<https://github.com/EmpaticoOrg/scenic-mysql_adapter>)
246
+ * [`scenic-sqlserver-adapter`](<https://github.com/ClickMechanic/scenic_sqlserver_adapter>)
247
+ * [`scenic-oracle_adapter`](<https://github.com/cdinger/scenic-oracle_adapter>)
259
248
 
260
249
  Please note that the maintainers of Scenic make no assertions about the
261
250
  quality or security of the above adapters.
262
251
 
263
252
  ## About
264
253
 
254
+ Scenic is used by some popular open source Rails apps:
255
+ [Mastodon](<https://github.com/mastodon/mastodon/>),
256
+ [Code.org](<https://github.com/code-dot-org/code-dot-org>), and
257
+ [Lobste.rs](<https://github.com/lobsters/lobsters/>).
258
+
265
259
  Scenic is maintained by [Derek Prior], [Caleb Hearth], and you, our
266
260
  contributors.
267
261
 
@@ -15,6 +15,11 @@ module Scenic
15
15
  required: false,
16
16
  desc: "Adds WITH NO DATA when materialized view creates/updates",
17
17
  default: false
18
+ class_option :replace,
19
+ type: :boolean,
20
+ required: false,
21
+ desc: "Uses replace_view instead of update_view",
22
+ default: false
18
23
  end
19
24
 
20
25
  private
@@ -23,6 +28,10 @@ module Scenic
23
28
  options[:materialized]
24
29
  end
25
30
 
31
+ def replace_view?
32
+ options[:replace]
33
+ end
34
+
26
35
  def no_data?
27
36
  options[:no_data]
28
37
  end
@@ -36,12 +36,23 @@ module Scenic
36
36
  def evaluate_template(source)
37
37
  source = File.expand_path(find_in_source_paths(source.to_s))
38
38
  context = instance_eval("binding", __FILE__, __LINE__)
39
- ERB.new(
40
- ::File.binread(source),
41
- nil,
42
- "-",
43
- "@output_buffer",
44
- ).result(context)
39
+
40
+ if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
41
+ erb = ERB.new(
42
+ ::File.binread(source),
43
+ trim_mode: "-",
44
+ eoutvar: "@output_buffer",
45
+ )
46
+ else
47
+ erb = ERB.new(
48
+ ::File.binread(source),
49
+ nil,
50
+ "-",
51
+ "@output_buffer",
52
+ )
53
+ end
54
+
55
+ erb.result(context)
45
56
  end
46
57
 
47
58
  def generating?
@@ -1,12 +1,13 @@
1
1
  class <%= migration_class_name %> < <%= activerecord_migration_class %>
2
2
  def change
3
+ <% method_name = replace_view? ? 'replace_view' : 'update_view' %>
3
4
  <%- if materialized? -%>
4
- update_view <%= formatted_plural_name %>,
5
+ <%= method_name %> <%= formatted_plural_name %>,
5
6
  version: <%= version %>,
6
7
  revert_to_version: <%= previous_version %>,
7
8
  materialized: <%= no_data? ? "{ no_data: true }" : true %>
8
9
  <%- else -%>
9
- update_view <%= formatted_plural_name %>, version: <%= version %>, revert_to_version: <%= previous_version %>
10
+ <%= method_name %> <%= formatted_plural_name %>, version: <%= version %>, revert_to_version: <%= previous_version %>
10
11
  <%- end -%>
11
12
  end
12
13
  end
@@ -1,3 +1,3 @@
1
1
  module Scenic
2
- VERSION = "1.6.0".freeze
2
+ VERSION = "1.7.0".freeze
3
3
  end
data/lib/scenic/view.rb CHANGED
@@ -26,7 +26,7 @@ module Scenic
26
26
  #
27
27
  # @param name [String] The name of the view.
28
28
  # @param definition [String] The SQL for the query that defines the view.
29
- # @param materialized [String] `true` if the view is materialized.
29
+ # @param materialized [Boolean] `true` if the view is materialized.
30
30
  def initialize(name:, definition:, materialized:)
31
31
  @name = name
32
32
  @definition = definition
@@ -37,6 +37,18 @@ describe Scenic::Generators::ViewGenerator, :generator do
37
37
  end
38
38
  end
39
39
 
40
+ it "uses 'replace_view' instead of 'update_view' if replace flag is set" do
41
+ with_view_definition("aired_episodes", 1, "hello") do
42
+ allow(Dir).to receive(:entries).and_return(["aired_episodes_v01.sql"])
43
+
44
+ run_generator ["aired_episode", "--replace"]
45
+ migration = migration_file(
46
+ "db/migrate/update_aired_episodes_to_version_2.rb",
47
+ )
48
+ expect(migration).to contain "replace_view"
49
+ end
50
+ end
51
+
40
52
  context "for views created in a schema other than 'public'" do
41
53
  it "creates a view definition" do
42
54
  view_definition = file("db/views/non_public_searches_v01.sql")
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.6.0
4
+ version: 1.7.0
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: 2022-02-13 00:00:00.000000000 Z
12
+ date: 2022-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -277,7 +277,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
277
277
  - !ruby/object:Gem::Version
278
278
  version: '0'
279
279
  requirements: []
280
- rubygems_version: 3.2.22
280
+ rubygems_version: 3.2.32
281
281
  signing_key:
282
282
  specification_version: 4
283
283
  summary: Support for database views in Rails migrations