scenic 1.5.5 → 1.6.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 +4 -4
- data/.devcontainer/Dockerfile +6 -0
- data/.devcontainer/devcontainer.json +11 -0
- data/.devcontainer/docker-compose.yml +24 -0
- data/.github/workflows/ci.yml +3 -3
- data/CHANGELOG.md +16 -0
- data/lib/scenic/adapters/postgres/views.rb +1 -0
- data/lib/scenic/definition.rb +4 -2
- data/lib/scenic/unaffixed_name.rb +31 -0
- data/lib/scenic/version.rb +1 -1
- data/lib/scenic/view.rb +6 -2
- data/lib/scenic.rb +1 -0
- data/spec/dummy/config/database.yml +1 -1
- data/spec/dummy/db/migrate/20220112154220_add_pg_stat_statements_extension.rb +5 -0
- data/spec/dummy/db/schema.rb +19 -0
- data/spec/scenic/definition_spec.rb +8 -0
- data/spec/scenic/schema_dumper_spec.rb +31 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/support/rails_configuration_helpers.rb +10 -0
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23461e20bd94ffe9d2466098b04141ef8b8256d83f6c05cf5c5d9f26cca08231
|
4
|
+
data.tar.gz: 6c331ddfc7c4d658b342367e2f2fcf703bf2b376314c32520d55afdbc05e936a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23e1ab6998fb898eebdc91691684bffc694fe51001ada435593cb9e6a3857074e13e6d1ba90333acf3a76069f2e687c129595389ce60ac7790bbb82cdfdd68c2
|
7
|
+
data.tar.gz: 2d91d5a48e68ef856ea9ffb14c3abb503fcaa1c588e17f55775ef32d2ae5f4f2862fd68aa53a99b2c666a0a81d88cba026fa21cdf2f4cc5b5e8a3f8062eb4779
|
@@ -0,0 +1,11 @@
|
|
1
|
+
{
|
2
|
+
"name": "Scenic Development",
|
3
|
+
"dockerComposeFile": "docker-compose.yml",
|
4
|
+
"service": "app",
|
5
|
+
"workspaceFolder": "/workspace",
|
6
|
+
"settings": { },
|
7
|
+
"extensions": ["rebornix.Ruby"],
|
8
|
+
"postCreateCommand": "bin/setup",
|
9
|
+
"remoteUser": "vscode",
|
10
|
+
"features": { "github-cli": "latest" }
|
11
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
version: '3'
|
2
|
+
|
3
|
+
services:
|
4
|
+
app:
|
5
|
+
build:
|
6
|
+
context: ..
|
7
|
+
dockerfile: .devcontainer/Dockerfile
|
8
|
+
args:
|
9
|
+
VARIANT: "3"
|
10
|
+
volumes:
|
11
|
+
- ..:/workspace:cached
|
12
|
+
command: sleep infinity
|
13
|
+
network_mode: service:db
|
14
|
+
db:
|
15
|
+
image: postgres:latest
|
16
|
+
restart: unless-stopped
|
17
|
+
volumes:
|
18
|
+
- postgres-data:/var/lib/postgresql/data
|
19
|
+
environment:
|
20
|
+
POSTGRES_USER: postgres
|
21
|
+
POSTGRES_DB: postgres
|
22
|
+
POSTGRES_PASSWORD: postgres
|
23
|
+
volumes:
|
24
|
+
postgres-data: null
|
data/.github/workflows/ci.yml
CHANGED
@@ -13,8 +13,8 @@ jobs:
|
|
13
13
|
strategy:
|
14
14
|
fail-fast: false
|
15
15
|
matrix:
|
16
|
-
ruby: ["2.7", "3.0"]
|
17
|
-
rails: ["6.
|
16
|
+
ruby: ["2.7", "3.0", "3.1"]
|
17
|
+
rails: ["6.1", "7.0", "master"]
|
18
18
|
continue-on-error: [false]
|
19
19
|
|
20
20
|
runs-on: ubuntu-latest
|
@@ -43,7 +43,7 @@ jobs:
|
|
43
43
|
uses: actions/checkout@v2
|
44
44
|
|
45
45
|
- name: Install Ruby ${{ matrix.ruby }}
|
46
|
-
uses: ruby/setup-ruby@v1
|
46
|
+
uses: ruby/setup-ruby@v1
|
47
47
|
with:
|
48
48
|
ruby-version: ${{ matrix.ruby }}
|
49
49
|
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,22 @@ 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
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
|
12
|
+
* Exclude pg_stat_statements_info (#349) 76bface
|
13
|
+
|
14
|
+
*Caleb Hearth*
|
15
|
+
|
16
|
+
* Fix serialization of views with backslashes c625d1b
|
17
|
+
|
18
|
+
*Ben Sheldon*
|
19
|
+
|
20
|
+
* Handle ActiveRecord table name prefix and suffix b1544dc
|
21
|
+
|
22
|
+
*Derek Prior*
|
23
|
+
|
8
24
|
## [1.5.5] - December 15, 2021
|
9
25
|
|
10
26
|
### Fixed
|
data/lib/scenic/definition.rb
CHANGED
@@ -2,7 +2,7 @@ module Scenic
|
|
2
2
|
# @api private
|
3
3
|
class Definition
|
4
4
|
def initialize(name, version)
|
5
|
-
@name = name
|
5
|
+
@name = name.to_s
|
6
6
|
@version = version.to_i
|
7
7
|
end
|
8
8
|
|
@@ -28,8 +28,10 @@ module Scenic
|
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
+
attr_reader :name
|
32
|
+
|
31
33
|
def filename
|
32
|
-
"#{
|
34
|
+
"#{UnaffixedName.for(name).tr('.', '_')}_v#{version}.sql"
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Scenic
|
2
|
+
# The name of a view or table according to rails.
|
3
|
+
#
|
4
|
+
# This removes any table name prefix or suffix that is configured via
|
5
|
+
# ActiveRecord. This allows, for example, the SchemaDumper to dump a view with
|
6
|
+
# its unaffixed name, consistent with how rails handles table dumping.
|
7
|
+
class UnaffixedName
|
8
|
+
# Gets the unaffixed name for the provided string
|
9
|
+
# @return [String]
|
10
|
+
#
|
11
|
+
# @param name [String] The (potentially) affixed view name
|
12
|
+
def self.for(name)
|
13
|
+
new(name, config: ActiveRecord::Base).call
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(name, config:)
|
17
|
+
@name = name
|
18
|
+
@config = config
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
prefix = Regexp.escape(config.table_name_prefix)
|
23
|
+
suffix = Regexp.escape(config.table_name_suffix)
|
24
|
+
name.sub(/\A#{prefix}(.+)#{suffix}\z/, "\\1")
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :name, :config
|
30
|
+
end
|
31
|
+
end
|
data/lib/scenic/version.rb
CHANGED
data/lib/scenic/view.rb
CHANGED
@@ -45,10 +45,14 @@ module Scenic
|
|
45
45
|
materialized_option = materialized ? "materialized: true, " : ""
|
46
46
|
|
47
47
|
<<-DEFINITION
|
48
|
-
create_view #{name.inspect}, #{materialized_option}sql_definition: <<-\SQL
|
49
|
-
#{
|
48
|
+
create_view #{UnaffixedName.for(name).inspect}, #{materialized_option}sql_definition: <<-\SQL
|
49
|
+
#{escaped_definition.indent(2)}
|
50
50
|
SQL
|
51
51
|
DEFINITION
|
52
52
|
end
|
53
|
+
|
54
|
+
def escaped_definition
|
55
|
+
definition.gsub("\\", "\\\\\\")
|
56
|
+
end
|
53
57
|
end
|
54
58
|
end
|
data/lib/scenic.rb
CHANGED
@@ -4,7 +4,7 @@ development: &default
|
|
4
4
|
encoding: unicode
|
5
5
|
host: localhost
|
6
6
|
pool: 5
|
7
|
-
<% if ENV.fetch("GITHUB_ACTIONS", false) %>
|
7
|
+
<% if ENV.fetch("GITHUB_ACTIONS", false) || ENV.fetch("CODESPACES", false) %>
|
8
8
|
username: <%= ENV.fetch("POSTGRES_USER") %>
|
9
9
|
password: <%= ENV.fetch("POSTGRES_PASSWORD") %>
|
10
10
|
<% end %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# This file is the source Rails uses to define your schema when running `bin/rails
|
6
|
+
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
|
7
|
+
# be faster and is potentially less error prone than running all of your
|
8
|
+
# migrations from scratch. Old migrations may fail to apply correctly if those
|
9
|
+
# migrations use external dependencies or application code.
|
10
|
+
#
|
11
|
+
# It's strongly recommended that you check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(version: 2022_01_12_154220) do
|
14
|
+
|
15
|
+
# These are extensions that must be enabled in order to support this database
|
16
|
+
enable_extension "pg_stat_statements"
|
17
|
+
enable_extension "plpgsql"
|
18
|
+
|
19
|
+
end
|
@@ -35,6 +35,14 @@ module Scenic
|
|
35
35
|
|
36
36
|
expect(definition.path).to eq "db/views/non_public_searches_v01.sql"
|
37
37
|
end
|
38
|
+
|
39
|
+
it "handles active record view prefix and suffixing" do
|
40
|
+
with_affixed_tables(prefix: "foo_", suffix: "_bar") do
|
41
|
+
definition = Definition.new("foo_searches_bar", 1)
|
42
|
+
|
43
|
+
expect(definition.path).to eq "db/views/searches_v01.sql"
|
44
|
+
end
|
45
|
+
end
|
38
46
|
end
|
39
47
|
|
40
48
|
describe "full_path" do
|
@@ -26,6 +26,22 @@ describe Scenic::SchemaDumper, :db do
|
|
26
26
|
expect(Search.first.haystack).to eq "needle"
|
27
27
|
end
|
28
28
|
|
29
|
+
it "accurately dumps create view statements with a regular expression" do
|
30
|
+
view_definition = "SELECT 'needle'::text AS haystack WHERE 'a2z' ~ '\\d+'"
|
31
|
+
Search.connection.create_view :searches, sql_definition: view_definition
|
32
|
+
stream = StringIO.new
|
33
|
+
|
34
|
+
ActiveRecord::SchemaDumper.dump(Search.connection, stream)
|
35
|
+
|
36
|
+
output = stream.string
|
37
|
+
expect(output).to include "~ '\\\\d+'::text"
|
38
|
+
|
39
|
+
Search.connection.drop_view :searches
|
40
|
+
silence_stream(STDOUT) { eval(output) }
|
41
|
+
|
42
|
+
expect(Search.first.haystack).to eq "needle"
|
43
|
+
end
|
44
|
+
|
29
45
|
it "dumps a create_view for a materialized view in the database" do
|
30
46
|
view_definition = "SELECT 'needle'::text AS haystack"
|
31
47
|
Search.connection.create_view :searches, materialized: true, sql_definition: view_definition
|
@@ -55,6 +71,20 @@ describe Scenic::SchemaDumper, :db do
|
|
55
71
|
end
|
56
72
|
end
|
57
73
|
|
74
|
+
it "handles active record table name prefixes and suffixes" do
|
75
|
+
with_affixed_tables(prefix: "a_", suffix: "_z") do
|
76
|
+
view_definition = "SELECT 'needle'::text AS haystack"
|
77
|
+
Search.connection.create_view :a_searches_z, sql_definition: view_definition
|
78
|
+
stream = StringIO.new
|
79
|
+
|
80
|
+
ActiveRecord::SchemaDumper.dump(Search.connection, stream)
|
81
|
+
|
82
|
+
output = stream.string
|
83
|
+
|
84
|
+
expect(output).to include 'create_view "searches"'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
58
88
|
it "ignores tables internal to Rails" do
|
59
89
|
view_definition = "SELECT 'needle'::text AS haystack"
|
60
90
|
Search.connection.create_view :searches, sql_definition: view_definition
|
@@ -65,7 +95,7 @@ describe Scenic::SchemaDumper, :db do
|
|
65
95
|
output = stream.string
|
66
96
|
|
67
97
|
expect(output).to include 'create_view "searches"'
|
68
|
-
expect(output).not_to include "
|
98
|
+
expect(output).not_to include "pg_stat_statements_info"
|
69
99
|
expect(output).not_to include "schema_migrations"
|
70
100
|
end
|
71
101
|
|
data/spec/spec_helper.rb
CHANGED
@@ -2,12 +2,14 @@ ENV["RAILS_ENV"] = "test"
|
|
2
2
|
require "database_cleaner"
|
3
3
|
|
4
4
|
require File.expand_path("dummy/config/environment", __dir__)
|
5
|
+
require "support/rails_configuration_helpers"
|
5
6
|
require "support/generator_spec_setup"
|
6
7
|
require "support/view_definition_helpers"
|
7
8
|
|
8
9
|
RSpec.configure do |config|
|
9
10
|
config.order = "random"
|
10
11
|
config.include ViewDefinitionHelpers
|
12
|
+
config.include RailsConfigurationHelpers
|
11
13
|
DatabaseCleaner.strategy = :transaction
|
12
14
|
|
13
15
|
config.around(:each, db: true) do |example|
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module RailsConfigurationHelpers
|
2
|
+
def with_affixed_tables(prefix: "", suffix: "")
|
3
|
+
ActiveRecord::Base.table_name_prefix = prefix
|
4
|
+
ActiveRecord::Base.table_name_suffix = suffix
|
5
|
+
yield
|
6
|
+
ensure
|
7
|
+
ActiveRecord::Base.table_name_prefix = ""
|
8
|
+
ActiveRecord::Base.table_name_suffix = ""
|
9
|
+
end
|
10
|
+
end
|
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.6.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:
|
12
|
+
date: 2022-02-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -175,6 +175,9 @@ executables: []
|
|
175
175
|
extensions: []
|
176
176
|
extra_rdoc_files: []
|
177
177
|
files:
|
178
|
+
- ".devcontainer/Dockerfile"
|
179
|
+
- ".devcontainer/devcontainer.json"
|
180
|
+
- ".devcontainer/docker-compose.yml"
|
178
181
|
- ".github/workflows/ci.yml"
|
179
182
|
- ".gitignore"
|
180
183
|
- ".hound.yml"
|
@@ -217,6 +220,7 @@ files:
|
|
217
220
|
- lib/scenic/railtie.rb
|
218
221
|
- lib/scenic/schema_dumper.rb
|
219
222
|
- lib/scenic/statements.rb
|
223
|
+
- lib/scenic/unaffixed_name.rb
|
220
224
|
- lib/scenic/version.rb
|
221
225
|
- lib/scenic/view.rb
|
222
226
|
- scenic.gemspec
|
@@ -234,6 +238,8 @@ files:
|
|
234
238
|
- spec/dummy/config/database.yml
|
235
239
|
- spec/dummy/config/environment.rb
|
236
240
|
- spec/dummy/db/migrate/.keep
|
241
|
+
- spec/dummy/db/migrate/20220112154220_add_pg_stat_statements_extension.rb
|
242
|
+
- spec/dummy/db/schema.rb
|
237
243
|
- spec/dummy/db/views/.keep
|
238
244
|
- spec/generators/scenic/model/model_generator_spec.rb
|
239
245
|
- spec/generators/scenic/view/view_generator_spec.rb
|
@@ -250,6 +256,7 @@ files:
|
|
250
256
|
- spec/scenic/statements_spec.rb
|
251
257
|
- spec/spec_helper.rb
|
252
258
|
- spec/support/generator_spec_setup.rb
|
259
|
+
- spec/support/rails_configuration_helpers.rb
|
253
260
|
- spec/support/view_definition_helpers.rb
|
254
261
|
homepage: https://github.com/scenic-views/scenic
|
255
262
|
licenses:
|
@@ -270,7 +277,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
270
277
|
- !ruby/object:Gem::Version
|
271
278
|
version: '0'
|
272
279
|
requirements: []
|
273
|
-
rubygems_version: 3.2.
|
280
|
+
rubygems_version: 3.2.22
|
274
281
|
signing_key:
|
275
282
|
specification_version: 4
|
276
283
|
summary: Support for database views in Rails migrations
|
@@ -289,6 +296,8 @@ test_files:
|
|
289
296
|
- spec/dummy/config/database.yml
|
290
297
|
- spec/dummy/config/environment.rb
|
291
298
|
- spec/dummy/db/migrate/.keep
|
299
|
+
- spec/dummy/db/migrate/20220112154220_add_pg_stat_statements_extension.rb
|
300
|
+
- spec/dummy/db/schema.rb
|
292
301
|
- spec/dummy/db/views/.keep
|
293
302
|
- spec/generators/scenic/model/model_generator_spec.rb
|
294
303
|
- spec/generators/scenic/view/view_generator_spec.rb
|
@@ -305,4 +314,5 @@ test_files:
|
|
305
314
|
- spec/scenic/statements_spec.rb
|
306
315
|
- spec/spec_helper.rb
|
307
316
|
- spec/support/generator_spec_setup.rb
|
317
|
+
- spec/support/rails_configuration_helpers.rb
|
308
318
|
- spec/support/view_definition_helpers.rb
|