scenic 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +10 -9
- data/NEWS.md +20 -0
- data/gemfiles/rails50.gemfile +1 -2
- data/lib/generators/scenic/view/templates/db/migrate/create_view.erb +1 -1
- data/lib/generators/scenic/view/templates/db/migrate/update_view.erb +2 -2
- data/lib/generators/scenic/view/view_generator.rb +13 -1
- data/lib/scenic/adapters/postgres/indexes.rb +1 -1
- data/lib/scenic/schema_dumper.rb +12 -5
- data/lib/scenic/version.rb +1 -1
- data/lib/scenic/view.rb +1 -1
- data/spec/generators/scenic/view/view_generator_spec.rb +12 -0
- data/spec/smoke +10 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1617d9008cabf9f0117f71f812735e8f89bf932
|
4
|
+
data.tar.gz: 31babdfa7c8fc2bc200f9457bc6f8fcab9f16a8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aebbd7f6d99c20b35420a68977a4231849543393c01d2a37487cfcde775cc26b33af792d13b61a4618db12dfe4eef0fc0a581ad27a5b76842d4701c0452302db
|
7
|
+
data.tar.gz: 05ea1809e4c4777903a297a9ee1e8c83d59ac3550aa455a82ef2d0e52f0a5f715211ed721e1f425aa87f4d08e7f04c7e7c9b1bec284861ab667e555eefe226c0
|
data/Appraisals
CHANGED
@@ -13,13 +13,14 @@ appraise "rails42" do
|
|
13
13
|
gem "railties", "~> 4.2.0"
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
if RUBY_VERSION > "2.2.0"
|
17
|
+
appraise "rails50" do
|
18
|
+
gem "rails", github: "rails/rails"
|
19
|
+
gem "rspec-rails", github: "rspec/rspec-rails"
|
20
|
+
gem "rspec-support", github: "rspec/rspec-support"
|
21
|
+
gem "rspec-core", github: "rspec/rspec-core"
|
22
|
+
gem "rspec-mocks", github: "rspec/rspec-mocks"
|
23
|
+
gem "rspec-expectations", github: "rspec/rspec-expectations"
|
24
|
+
gem "rspec", github: "rspec/rspec"
|
25
|
+
end
|
25
26
|
end
|
data/NEWS.md
CHANGED
@@ -5,6 +5,26 @@ changelog, see the [CHANGELOG] for each version via the version links.
|
|
5
5
|
|
6
6
|
[CHANGELOG]: https://github.com/thoughtbot/scenic/commits/master
|
7
7
|
|
8
|
+
## [1.2.0] - February 5, 2016
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- The generators now accept namespaced view definitions. For example: `rails
|
12
|
+
generate scenic:view my_app.users`.
|
13
|
+
|
14
|
+
### Fixed
|
15
|
+
- Materialized view indexes are now properly dumped to `db/schema.rb`. This was
|
16
|
+
an oversight in previous releases, meaning `rake db:schema:load` was missing
|
17
|
+
indexes.
|
18
|
+
- Calling `update_view` for a materialized view now properly finds associated
|
19
|
+
indexes for automatic reapplication. An issue in the previous index query was
|
20
|
+
returning no indexes.
|
21
|
+
|
22
|
+
**Note**: Dumping materialized view indexes will produce an invalid
|
23
|
+
`db/schema.rb` file under Rails 5 beta 1 and beta 2. This is fixed on Rails
|
24
|
+
master.
|
25
|
+
|
26
|
+
[1.2.0]: https://github.com/thoughtbot/scenic/compare/v1.1.1...v1.2.0
|
27
|
+
|
8
28
|
## [1.1.1] - January 29, 2016
|
9
29
|
|
10
30
|
### Fixed
|
data/gemfiles/rails50.gemfile
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "
|
6
|
-
gem "railties", "~> 5.0.0.beta1"
|
5
|
+
gem "rails", :github => "rails/rails"
|
7
6
|
gem "rspec-rails", :github => "rspec/rspec-rails"
|
8
7
|
gem "rspec-support", :github => "rspec/rspec-support"
|
9
8
|
gem "rspec-core", :github => "rspec/rspec-core"
|
@@ -1,12 +1,12 @@
|
|
1
1
|
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
<%- if materialized? -%>
|
4
|
-
update_view
|
4
|
+
update_view <%= formatted_plural_name %>,
|
5
5
|
version: <%= version %>,
|
6
6
|
revert_to_version: <%= previous_version %>,
|
7
7
|
materialized: true
|
8
8
|
<%- else -%>
|
9
|
-
update_view
|
9
|
+
update_view <%= formatted_plural_name %>, version: <%= version %>, revert_to_version: <%= previous_version %>
|
10
10
|
<%- end -%>
|
11
11
|
end
|
12
12
|
end
|
@@ -56,7 +56,7 @@ module Scenic
|
|
56
56
|
|
57
57
|
def migration_class_name
|
58
58
|
if creating_new_view?
|
59
|
-
|
59
|
+
"Create#{class_name.gsub('.', '').pluralize}"
|
60
60
|
else
|
61
61
|
"Update#{class_name.pluralize}ToVersion#{version}"
|
62
62
|
end
|
@@ -85,10 +85,22 @@ module Scenic
|
|
85
85
|
Scenic::Definition.new(plural_file_name, previous_version)
|
86
86
|
end
|
87
87
|
|
88
|
+
def plural_file_name
|
89
|
+
@plural_file_name ||= file_name.pluralize.gsub(".", "_")
|
90
|
+
end
|
91
|
+
|
88
92
|
def destroying?
|
89
93
|
behavior == :revoke
|
90
94
|
end
|
91
95
|
|
96
|
+
def formatted_plural_name
|
97
|
+
if plural_name.include?(".")
|
98
|
+
"\"#{plural_name}\""
|
99
|
+
else
|
100
|
+
":#{plural_name}"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
92
104
|
def destroying_initial_view?
|
93
105
|
destroying? && version == 1
|
94
106
|
end
|
@@ -34,7 +34,7 @@ module Scenic
|
|
34
34
|
LEFT JOIN pg_namespace n ON n.oid = i.relnamespace
|
35
35
|
WHERE i.relkind = 'i'
|
36
36
|
AND d.indisprimary = 'f'
|
37
|
-
AND t.relname = '#{
|
37
|
+
AND t.relname = '#{name}'
|
38
38
|
AND n.nspname = ANY (current_schemas(false))
|
39
39
|
ORDER BY i.relname
|
40
40
|
SQL
|
data/lib/scenic/schema_dumper.rb
CHANGED
@@ -9,17 +9,24 @@ module Scenic
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def views(stream)
|
12
|
-
|
13
|
-
stream.puts
|
12
|
+
if dumpable_views_in_database.any?
|
13
|
+
stream.puts
|
14
14
|
end
|
15
|
-
end
|
16
15
|
|
17
|
-
|
18
|
-
|
16
|
+
dumpable_views_in_database.each do |view|
|
17
|
+
stream.puts(view.to_schema)
|
18
|
+
indexes(view.name, stream)
|
19
|
+
end
|
19
20
|
end
|
20
21
|
|
21
22
|
private
|
22
23
|
|
24
|
+
def dumpable_views_in_database
|
25
|
+
@dumpable_views_in_database ||= Scenic.database.views.reject do |view|
|
26
|
+
ignored?(view.name)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
23
30
|
unless ActiveRecord::SchemaDumper.instance_methods(false).include?(:ignored?)
|
24
31
|
# This method will be present in Rails 4.2.0 and can be removed then.
|
25
32
|
def ignored?(table_name)
|
data/lib/scenic/version.rb
CHANGED
data/lib/scenic/view.rb
CHANGED
@@ -44,10 +44,10 @@ module Scenic
|
|
44
44
|
def to_schema
|
45
45
|
materialized_option = materialized ? "materialized: true, " : ""
|
46
46
|
<<-DEFINITION
|
47
|
-
|
48
47
|
create_view :#{name}, #{materialized_option} sql_definition: <<-\SQL
|
49
48
|
#{definition.indent(2)}
|
50
49
|
SQL
|
50
|
+
|
51
51
|
DEFINITION
|
52
52
|
end
|
53
53
|
end
|
@@ -36,4 +36,16 @@ describe Scenic::Generators::ViewGenerator, :generator do
|
|
36
36
|
expect(migration).to contain "materialized: true"
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
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")
|
43
|
+
view_definition = file("db/views/non_public_searches_v01.sql")
|
44
|
+
|
45
|
+
run_generator ["non_public.search"]
|
46
|
+
|
47
|
+
expect(migration).to be_a_migration
|
48
|
+
expect(view_definition).to exist
|
49
|
+
end
|
50
|
+
end
|
39
51
|
end
|
data/spec/smoke
CHANGED
@@ -26,6 +26,13 @@ verifySearchResults() {
|
|
26
26
|
echo "[success]"
|
27
27
|
}
|
28
28
|
|
29
|
+
verifySchemaContains() {
|
30
|
+
local expectedString=$1
|
31
|
+
echo "verify schema contains '$expectedString'"
|
32
|
+
grep -q "$expectedString" db/schema.rb || exit 1
|
33
|
+
echo "[success]"
|
34
|
+
}
|
35
|
+
|
29
36
|
writeToFileAndMigrateAndVerifySearchResults() {
|
30
37
|
echo "write search definition and migrate"
|
31
38
|
local version=$1
|
@@ -98,8 +105,8 @@ main() {
|
|
98
105
|
echo "[success]"
|
99
106
|
|
100
107
|
echo "add indexes to materialized view"
|
101
|
-
rails runner
|
102
|
-
rails runner
|
108
|
+
rails runner 'ActiveRecord::Migration.add_index :searches, :results' || exit 1
|
109
|
+
rails runner 'ActiveRecord::Migration.add_index :searches, :user_id' || exit 1
|
103
110
|
echo "[success]"
|
104
111
|
|
105
112
|
echo "update materialized view"
|
@@ -107,6 +114,7 @@ main() {
|
|
107
114
|
echo "SELECT 'test'::text AS results" > db/views/searches_v02.sql
|
108
115
|
rake db:migrate
|
109
116
|
verifySearchResults 'test'
|
117
|
+
verifySchemaContains 'add_index "searches"'
|
110
118
|
|
111
119
|
echo "rake db:rollback"
|
112
120
|
rake db:rollback
|
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.
|
4
|
+
version: 1.2.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: 2016-
|
12
|
+
date: 2016-02-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: appraisal
|
@@ -282,7 +282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
282
282
|
version: '0'
|
283
283
|
requirements: []
|
284
284
|
rubyforge_project:
|
285
|
-
rubygems_version: 2.
|
285
|
+
rubygems_version: 2.2.5
|
286
286
|
signing_key:
|
287
287
|
specification_version: 4
|
288
288
|
summary: Support for database views in Rails migrations
|