schema_plus_views 0.3.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/prs.yml +194 -0
- data/.gitignore +1 -0
- data/.simplecov +20 -0
- data/Gemfile +4 -1
- data/README.md +58 -31
- data/Rakefile +2 -0
- data/gemfiles/Gemfile.base +1 -1
- data/gemfiles/activerecord-5.2/Gemfile.base +4 -0
- data/gemfiles/activerecord-5.2/Gemfile.mysql2 +10 -0
- data/gemfiles/activerecord-5.2/Gemfile.postgresql +10 -0
- data/gemfiles/{activerecord-4.2 → activerecord-5.2}/Gemfile.sqlite3 +3 -3
- data/gemfiles/activerecord-6.0/Gemfile.base +4 -0
- data/gemfiles/activerecord-6.0/Gemfile.mysql2 +10 -0
- data/gemfiles/activerecord-6.0/Gemfile.postgresql +10 -0
- data/gemfiles/activerecord-6.0/Gemfile.sqlite3 +10 -0
- data/lib/schema_plus/views/active_record/connection_adapters/abstract_adapter.rb +21 -5
- data/lib/schema_plus/views/active_record/connection_adapters/mysql2_adapter.rb +7 -11
- data/lib/schema_plus/views/active_record/connection_adapters/postgresql_adapter.rb +76 -17
- data/lib/schema_plus/views/active_record/connection_adapters/sqlite3_adapter.rb +7 -9
- data/lib/schema_plus/views/active_record/migration/command_recorder.rb +5 -1
- data/lib/schema_plus/views/middleware.rb +35 -34
- data/lib/schema_plus/views/schema_dump.rb +28 -0
- data/lib/schema_plus/views/version.rb +3 -1
- data/lib/schema_plus/views.rb +3 -0
- data/lib/schema_plus_views.rb +2 -0
- data/schema_dev.yml +7 -2
- data/schema_plus_views.gemspec +10 -9
- data/spec/dumper_spec.rb +60 -10
- data/spec/introspection_spec.rb +54 -6
- data/spec/middleware_spec.rb +3 -18
- data/spec/migration_spec.rb +108 -58
- data/spec/named_schemas_spec.rb +10 -42
- data/spec/sanity_spec.rb +2 -0
- data/spec/spec_helper.rb +16 -3
- metadata +39 -56
- data/.travis.yml +0 -18
- data/gemfiles/activerecord-4.2/Gemfile.base +0 -3
- data/gemfiles/activerecord-4.2/Gemfile.mysql2 +0 -10
- data/gemfiles/activerecord-4.2/Gemfile.postgresql +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b6dc17514d0000f4bdfee9c6840afec09ce47fa0635d89cefbc82667f197b904
|
4
|
+
data.tar.gz: b12b99196f5d28b120e97aae3bd7bfc698a7e004439b6e0538ffbc2c079ecd13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03666f035ea72b9f03a6ff2d20321adb8a1adb7e0c13682229e3f9f52e7c94876408e9597eb4c42c8b6eac5ae6c046c826d3cc7daa8ed2ab4b4afbf00326ba82
|
7
|
+
data.tar.gz: 192ccf942b56d1d09409895d7b9c9eb9693ec30fa497ddad80ec5114c0090f4d13a6db37ea070b3df124bd1e65af5d8069a2fcf76b56206aa0436745568a8d4f
|
@@ -0,0 +1,194 @@
|
|
1
|
+
# This file was auto-generated by the schema_dev tool, based on the data in
|
2
|
+
# ./schema_dev.yml
|
3
|
+
# Please do not edit this file; any changes will be overwritten next time
|
4
|
+
# schema_dev gets run.
|
5
|
+
---
|
6
|
+
name: CI PR Builds
|
7
|
+
'on':
|
8
|
+
push:
|
9
|
+
branches:
|
10
|
+
- master
|
11
|
+
pull_request:
|
12
|
+
concurrency:
|
13
|
+
group: ci-${{ github.ref }}
|
14
|
+
cancel-in-progress: true
|
15
|
+
jobs:
|
16
|
+
test:
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
strategy:
|
19
|
+
fail-fast: false
|
20
|
+
matrix:
|
21
|
+
ruby:
|
22
|
+
- '2.5'
|
23
|
+
- '2.7'
|
24
|
+
- '3.0'
|
25
|
+
activerecord:
|
26
|
+
- '5.2'
|
27
|
+
- '6.0'
|
28
|
+
db:
|
29
|
+
- mysql2
|
30
|
+
- sqlite3
|
31
|
+
- skip
|
32
|
+
dbversion:
|
33
|
+
- skip
|
34
|
+
exclude:
|
35
|
+
- ruby: '3.0'
|
36
|
+
activerecord: '5.2'
|
37
|
+
- db: skip
|
38
|
+
dbversion: skip
|
39
|
+
include:
|
40
|
+
- ruby: '2.5'
|
41
|
+
activerecord: '5.2'
|
42
|
+
db: postgresql
|
43
|
+
dbversion: '9.6'
|
44
|
+
- ruby: '2.5'
|
45
|
+
activerecord: '5.2'
|
46
|
+
db: postgresql
|
47
|
+
dbversion: '10'
|
48
|
+
- ruby: '2.5'
|
49
|
+
activerecord: '5.2'
|
50
|
+
db: postgresql
|
51
|
+
dbversion: '11'
|
52
|
+
- ruby: '2.5'
|
53
|
+
activerecord: '5.2'
|
54
|
+
db: postgresql
|
55
|
+
dbversion: '12'
|
56
|
+
- ruby: '2.5'
|
57
|
+
activerecord: '6.0'
|
58
|
+
db: postgresql
|
59
|
+
dbversion: '9.6'
|
60
|
+
- ruby: '2.5'
|
61
|
+
activerecord: '6.0'
|
62
|
+
db: postgresql
|
63
|
+
dbversion: '10'
|
64
|
+
- ruby: '2.5'
|
65
|
+
activerecord: '6.0'
|
66
|
+
db: postgresql
|
67
|
+
dbversion: '11'
|
68
|
+
- ruby: '2.5'
|
69
|
+
activerecord: '6.0'
|
70
|
+
db: postgresql
|
71
|
+
dbversion: '12'
|
72
|
+
- ruby: '2.7'
|
73
|
+
activerecord: '5.2'
|
74
|
+
db: postgresql
|
75
|
+
dbversion: '9.6'
|
76
|
+
- ruby: '2.7'
|
77
|
+
activerecord: '5.2'
|
78
|
+
db: postgresql
|
79
|
+
dbversion: '10'
|
80
|
+
- ruby: '2.7'
|
81
|
+
activerecord: '5.2'
|
82
|
+
db: postgresql
|
83
|
+
dbversion: '11'
|
84
|
+
- ruby: '2.7'
|
85
|
+
activerecord: '5.2'
|
86
|
+
db: postgresql
|
87
|
+
dbversion: '12'
|
88
|
+
- ruby: '2.7'
|
89
|
+
activerecord: '6.0'
|
90
|
+
db: postgresql
|
91
|
+
dbversion: '9.6'
|
92
|
+
- ruby: '2.7'
|
93
|
+
activerecord: '6.0'
|
94
|
+
db: postgresql
|
95
|
+
dbversion: '10'
|
96
|
+
- ruby: '2.7'
|
97
|
+
activerecord: '6.0'
|
98
|
+
db: postgresql
|
99
|
+
dbversion: '11'
|
100
|
+
- ruby: '2.7'
|
101
|
+
activerecord: '6.0'
|
102
|
+
db: postgresql
|
103
|
+
dbversion: '12'
|
104
|
+
- ruby: '3.0'
|
105
|
+
activerecord: '6.0'
|
106
|
+
db: postgresql
|
107
|
+
dbversion: '9.6'
|
108
|
+
- ruby: '3.0'
|
109
|
+
activerecord: '6.0'
|
110
|
+
db: postgresql
|
111
|
+
dbversion: '10'
|
112
|
+
- ruby: '3.0'
|
113
|
+
activerecord: '6.0'
|
114
|
+
db: postgresql
|
115
|
+
dbversion: '11'
|
116
|
+
- ruby: '3.0'
|
117
|
+
activerecord: '6.0'
|
118
|
+
db: postgresql
|
119
|
+
dbversion: '12'
|
120
|
+
env:
|
121
|
+
BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}/Gemfile.${{ matrix.db }}"
|
122
|
+
MYSQL_DB_HOST: 127.0.0.1
|
123
|
+
MYSQL_DB_USER: root
|
124
|
+
MYSQL_DB_PASS: database
|
125
|
+
POSTGRESQL_DB_HOST: 127.0.0.1
|
126
|
+
POSTGRESQL_DB_USER: schema_plus_test
|
127
|
+
POSTGRESQL_DB_PASS: database
|
128
|
+
steps:
|
129
|
+
- uses: actions/checkout@v2
|
130
|
+
- name: Set up Ruby
|
131
|
+
uses: ruby/setup-ruby@v1
|
132
|
+
with:
|
133
|
+
ruby-version: "${{ matrix.ruby }}"
|
134
|
+
bundler-cache: true
|
135
|
+
- name: Run bundle update
|
136
|
+
run: bundle update
|
137
|
+
- name: Start Mysql
|
138
|
+
if: matrix.db == 'mysql2'
|
139
|
+
run: |
|
140
|
+
docker run --rm --detach \
|
141
|
+
-e MYSQL_ROOT_PASSWORD=$MYSQL_DB_PASS \
|
142
|
+
-p 3306:3306 \
|
143
|
+
--health-cmd "mysqladmin ping --host=127.0.0.1 --password=$MYSQL_DB_PASS --silent" \
|
144
|
+
--health-interval 5s \
|
145
|
+
--health-timeout 5s \
|
146
|
+
--health-retries 5 \
|
147
|
+
--name database mysql:5.6
|
148
|
+
- name: Start Postgresql
|
149
|
+
if: matrix.db == 'postgresql'
|
150
|
+
run: |
|
151
|
+
docker run --rm --detach \
|
152
|
+
-e POSTGRES_USER=$POSTGRESQL_DB_USER \
|
153
|
+
-e POSTGRES_PASSWORD=$POSTGRESQL_DB_PASS \
|
154
|
+
-p 5432:5432 \
|
155
|
+
--health-cmd "pg_isready -q" \
|
156
|
+
--health-interval 5s \
|
157
|
+
--health-timeout 5s \
|
158
|
+
--health-retries 5 \
|
159
|
+
--name database postgres:${{ matrix.dbversion }}
|
160
|
+
- name: Wait for database to start
|
161
|
+
if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
|
162
|
+
run: |
|
163
|
+
COUNT=0
|
164
|
+
ATTEMPTS=20
|
165
|
+
until [[ $COUNT -eq $ATTEMPTS ]]; do
|
166
|
+
[ "$(docker inspect -f {{.State.Health.Status}} database)" == "healthy" ] && break
|
167
|
+
echo $(( COUNT++ )) > /dev/null
|
168
|
+
sleep 2
|
169
|
+
done
|
170
|
+
- name: Create testing database
|
171
|
+
if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
|
172
|
+
run: bundle exec rake create_ci_database
|
173
|
+
- name: Run tests
|
174
|
+
run: bundle exec rake spec
|
175
|
+
- name: Shutdown database
|
176
|
+
if: always() && (matrix.db == 'postgresql' || matrix.db == 'mysql2')
|
177
|
+
run: docker stop database
|
178
|
+
- name: Coveralls Parallel
|
179
|
+
if: "${{ !env.ACT }}"
|
180
|
+
uses: coverallsapp/github-action@master
|
181
|
+
with:
|
182
|
+
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
183
|
+
flag-name: run-${{ matrix.ruby }}-${{ matrix.activerecord }}-${{ matrix.db }}-${{ matrix.dbversion }}
|
184
|
+
parallel: true
|
185
|
+
finish:
|
186
|
+
needs: test
|
187
|
+
runs-on: ubuntu-latest
|
188
|
+
steps:
|
189
|
+
- name: Coveralls Finished
|
190
|
+
if: "${{ !env.ACT }}"
|
191
|
+
uses: coverallsapp/github-action@master
|
192
|
+
with:
|
193
|
+
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
194
|
+
parallel-finished: true
|
data/.gitignore
CHANGED
data/.simplecov
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
SimpleCov.configure do
|
4
|
+
enable_coverage :branch
|
5
|
+
add_filter '/spec/'
|
6
|
+
|
7
|
+
add_group 'Binaries', '/bin/'
|
8
|
+
add_group 'Libraries', '/lib/'
|
9
|
+
|
10
|
+
if ENV['CI']
|
11
|
+
require 'simplecov-lcov'
|
12
|
+
|
13
|
+
SimpleCov::Formatter::LcovFormatter.config do |c|
|
14
|
+
c.report_with_single_file = true
|
15
|
+
c.single_report_path = 'coverage/lcov.info'
|
16
|
+
end
|
17
|
+
|
18
|
+
formatter SimpleCov::Formatter::LcovFormatter
|
19
|
+
end
|
20
|
+
end
|
data/Gemfile
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source "http://rubygems.org"
|
2
4
|
|
3
5
|
gemspec
|
4
6
|
|
5
|
-
|
7
|
+
gemfile_local = File.expand_path '../Gemfile.local', __FILE__
|
8
|
+
eval File.read(gemfile_local), binding, gemfile_local if File.exist? gemfile_local
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/schema_plus_views.svg)](http://badge.fury.io/rb/schema_plus_views)
|
2
|
-
[![Build Status](https://
|
3
|
-
[![Coverage Status](https://
|
4
|
-
[![Dependency Status](https://gemnasium.com/lomba/schema_plus_views.svg)](https://gemnasium.com/SchemaPlus/schema_plus_views)
|
2
|
+
[![Build Status](https://github.com/SchemaPlus/schema_plus_views/actions/workflows/pr.yml/badge.svg)](http://github.com/SchemaPlus/schema_plus_views/actions)
|
3
|
+
[![Coverage Status](https://coveralls.io/github/SchemaPlus/schema_plus_views/badge.svg)](https://coveralls.io/github/SchemaPlus/schema_plus_views)
|
5
4
|
|
6
5
|
# SchemaPlus::Views
|
7
6
|
|
@@ -28,7 +27,11 @@ SchemaPlus::Views is tested on:
|
|
28
27
|
|
29
28
|
<!-- SCHEMA_DEV: MATRIX - begin -->
|
30
29
|
<!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
|
31
|
-
* ruby **2.
|
30
|
+
* ruby **2.5** with activerecord **5.2**, using **mysql2**, **sqlite3**, **postgresql:9.6**, **postgresql:10**, **postgresql:11** or **postgresql:12**
|
31
|
+
* ruby **2.5** with activerecord **6.0**, using **mysql2**, **sqlite3**, **postgresql:9.6**, **postgresql:10**, **postgresql:11** or **postgresql:12**
|
32
|
+
* ruby **2.7** with activerecord **5.2**, using **mysql2**, **sqlite3**, **postgresql:9.6**, **postgresql:10**, **postgresql:11** or **postgresql:12**
|
33
|
+
* ruby **2.7** with activerecord **6.0**, using **mysql2**, **sqlite3**, **postgresql:9.6**, **postgresql:10**, **postgresql:11** or **postgresql:12**
|
34
|
+
* ruby **3.0** with activerecord **6.0**, using **mysql2**, **sqlite3**, **postgresql:9.6**, **postgresql:10**, **postgresql:11** or **postgresql:12**
|
32
35
|
|
33
36
|
<!-- SCHEMA_DEV: MATRIX - end -->
|
34
37
|
|
@@ -56,8 +59,30 @@ Additional options can be provided:
|
|
56
59
|
|
57
60
|
* `:allow_replace => true` will use the command "CREATE OR REPLACE" when creating the view, for seamlessly redefining the view even if other views depend on it. It's only supported by MySQL and PostgreSQL, and each has some limitations on when a view can be replaced; see their docs for details.
|
58
61
|
|
62
|
+
* `:materialized => true` will create a materialized view instead of a standard view. This view caches its contents on disk and must be refreshed to update its contents. It is only supported on PostgreSQL. Further, allow_replace is not supported on materialized views.
|
63
|
+
|
59
64
|
SchemaPlus::Views also arranges to include the `create_view` statements (with literal SQL) in the schema dump.
|
60
65
|
|
66
|
+
#### Materialized views
|
67
|
+
|
68
|
+
Materialized views persist their data when created and must be manually refreshed to see new data.
|
69
|
+
Further materialized views can have indexes defined on them.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
create_view :posts_commented_by_staff, <<~SQL, materialized: true
|
73
|
+
SELECT * FROM posts LEFT OUTER JOIN comments ON comments.post_id = posts.id WHERE comments.id IS NULL
|
74
|
+
SQL
|
75
|
+
|
76
|
+
add_index :posts_commented_by_staff, :category
|
77
|
+
add_index :posts_commented_by_staff, :token, unique: true
|
78
|
+
```
|
79
|
+
|
80
|
+
To refresh a materialized view run the refresh_view connection command.
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
ActiveRecord::Base.connection.refresh_view('posts_commented_by_staff')
|
84
|
+
```
|
85
|
+
|
61
86
|
### Dropping views
|
62
87
|
|
63
88
|
In a migration:
|
@@ -65,6 +90,10 @@ In a migration:
|
|
65
90
|
```ruby
|
66
91
|
drop_view :posts_commented_by_staff
|
67
92
|
drop_view :uncommented_posts, :if_exists => true
|
93
|
+
|
94
|
+
# materialized views
|
95
|
+
drop_view :posts_commented_by_staff, materialized: true
|
96
|
+
drop_view :uncommented_posts, :if_exists => true, materialized: true
|
68
97
|
```
|
69
98
|
|
70
99
|
### Using views
|
@@ -86,14 +115,16 @@ You can look up the defined views analogously to looking up tables:
|
|
86
115
|
|
87
116
|
```ruby
|
88
117
|
connection.tables # => array of table names [method provided by ActiveRecord]
|
89
|
-
connection.views # => array of view names [method
|
118
|
+
connection.views # => array of view names [method overridden by SchemaPlus::Views for postgres]
|
90
119
|
```
|
91
120
|
|
92
121
|
Notes:
|
93
122
|
|
94
|
-
1. For
|
95
|
-
|
96
|
-
|
123
|
+
1. For PostgreSQL, `connection.views` suppresses views prefixed with `pg_` as those are presumed to be internal. Also it suppresses the "postgis" specifically named tables
|
124
|
+
- geography_columns
|
125
|
+
- geometry_columns
|
126
|
+
- raster_columns
|
127
|
+
- raster_overviews
|
97
128
|
|
98
129
|
### Querying view definitions
|
99
130
|
|
@@ -105,26 +136,19 @@ connection.view_definition(view_name) # => returns SQL string
|
|
105
136
|
|
106
137
|
This returns just the body of the definition, i.e. the part after the `CREATE VIEW 'name' AS` command.
|
107
138
|
|
108
|
-
|
139
|
+
You can also lookup the type of view (regular or materialized) using
|
109
140
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
### `Schema::Views` stack
|
114
|
-
|
115
|
-
Wraps the `connection.views` method. Env contains:
|
141
|
+
```ruby
|
142
|
+
connection.view_type(view_name) # => returns a Symbol, either :view or :materialized
|
143
|
+
```
|
116
144
|
|
117
|
-
|
118
|
-
--- | --- | ---
|
119
|
-
`:views` | The result of the lookup | `[]`
|
120
|
-
`:connection` | The current ActiveRecord connection | *context*
|
121
|
-
`:query_name` | Optional label for ActiveRecord logging | *arg*
|
145
|
+
## Customization API: Middleware Stacks
|
122
146
|
|
123
|
-
|
147
|
+
All the methods defined by SchemaPlus::Views provide middleware stacks, in case you need to do any custom filtering, rewriting, triggering, or whatever. For info on how to use middleware stacks, see the READMEs of [schema_monkey](https://github.com/SchemaPlus/schema_monkey) and [schema_plus_core](https://github.com/SchemaPlus/schema_plus_core).
|
124
148
|
|
125
149
|
### `Schema::ViewDefinition` stack
|
126
150
|
|
127
|
-
Wraps the `connection.
|
151
|
+
Wraps the `connection.view_full_definition` method. Env contains:
|
128
152
|
|
129
153
|
Env Field | Description | Initialized
|
130
154
|
--- | --- | ---
|
@@ -132,6 +156,7 @@ Env Field | Description | Initialized
|
|
132
156
|
`:view_name` | The view to look up | *arg*
|
133
157
|
`:query_name` | Optional label for ActiveRecord logging | *arg*
|
134
158
|
`:definition` | The view definition SQL | `nil`
|
159
|
+
`:view_type` | The view type symbol. | :view`
|
135
160
|
|
136
161
|
The base implementation looks up the definition of the view named
|
137
162
|
`env.view_name` and assigns the result to `env.definition`
|
@@ -166,15 +191,18 @@ options in `env.options`
|
|
166
191
|
|
167
192
|
## History
|
168
193
|
|
169
|
-
* 0.
|
170
|
-
* 0.
|
194
|
+
* **1.0.0** - Add ruby 3 and AR 6.0, drop Ruy < 2.5
|
195
|
+
* **0.4.1** - Corrected spacing around dumped schema
|
196
|
+
* **0.4.0** - Added support for Rails 5.2 and materialized views in PostgreSQL
|
197
|
+
* **0.3.1** - Upgrade schema_plus_core and schema_dev dependencies
|
198
|
+
* **0.3.0**
|
171
199
|
- Added middleware stacks
|
172
200
|
- Bug fix: view_definition: strip white space from result (postgresql)
|
173
|
-
* 0.2.3 - Remove unnecessary escaping in dump; use single-quote heredoc
|
174
|
-
* 0.2.2 - Prettier dumps: use heredoc for definition string
|
175
|
-
* 0.2.1 - Fix db:rollback
|
176
|
-
* 0.2.0 - Added :allow_replace option (thanks to [@hcarver](https://github.com/hcarver))
|
177
|
-
* 0.1.0 - Initial release, extracted from schema_plus 1.x
|
201
|
+
* **0.2.3** - Remove unnecessary escaping in dump; use single-quote heredoc
|
202
|
+
* **0.2.2** - Prettier dumps: use heredoc for definition string
|
203
|
+
* **0.2.1** - Fix db:rollback
|
204
|
+
* **0.2.0** - Added :allow_replace option (thanks to [@hcarver](https://github.com/hcarver))
|
205
|
+
* **0.1.0** - Initial release, extracted from schema_plus 1.x
|
178
206
|
|
179
207
|
## Development & Testing
|
180
208
|
|
@@ -187,7 +215,7 @@ Some things to know about to help you develop and test:
|
|
187
215
|
* **schema_dev**: SchemaPlus::Views uses [schema_dev](https://github.com/SchemaPlus/schema_dev) to
|
188
216
|
facilitate running rspec tests on the matrix of ruby, activerecord, and database
|
189
217
|
versions that the gem supports, both locally and on
|
190
|
-
[
|
218
|
+
[github actions](https://github.com/SchemaPlus/schema_plus_views/actions)
|
191
219
|
|
192
220
|
To to run rspec locally on the full matrix, do:
|
193
221
|
|
@@ -199,7 +227,6 @@ Some things to know about to help you develop and test:
|
|
199
227
|
The matrix of configurations is specified in `schema_dev.yml` in
|
200
228
|
the project root.
|
201
229
|
|
202
|
-
|
203
230
|
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_DEV - end -->
|
204
231
|
|
205
232
|
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_PLUS_CORE - begin -->
|
data/Rakefile
CHANGED
data/gemfiles/Gemfile.base
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
eval
|
1
|
+
base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
|
2
|
+
eval File.read(base_gemfile), binding, base_gemfile
|
3
3
|
|
4
4
|
platform :ruby do
|
5
5
|
gem "sqlite3"
|
@@ -7,4 +7,4 @@ end
|
|
7
7
|
|
8
8
|
platform :jruby do
|
9
9
|
gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
|
10
|
-
end
|
10
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SchemaPlus::Views
|
2
4
|
module ActiveRecord
|
3
5
|
module ConnectionAdapters
|
@@ -6,6 +8,7 @@ module SchemaPlus::Views
|
|
6
8
|
# to first drop the view if it already exists.
|
7
9
|
def create_view(view_name, definition, options={})
|
8
10
|
SchemaMonkey::Middleware::Migration::CreateView.start(connection: self, view_name: view_name, definition: definition, options: options) do |env|
|
11
|
+
raise ArgumentError, 'Materialized views are not implemented or supported on this database' if options[:materialized]
|
9
12
|
definition = env.definition
|
10
13
|
view_name = env.view_name
|
11
14
|
options = env.options
|
@@ -28,6 +31,7 @@ module SchemaPlus::Views
|
|
28
31
|
# to fail silently if the view doesn't exist.
|
29
32
|
def drop_view(view_name, options = {})
|
30
33
|
SchemaMonkey::Middleware::Migration::DropView.start(connection: self, view_name: view_name, options: options) do |env|
|
34
|
+
raise ArgumentError, 'Materialized views are not implemented or supported on this database' if options[:materialized]
|
31
35
|
view_name = env.view_name
|
32
36
|
options = env.options
|
33
37
|
sql = "DROP VIEW"
|
@@ -37,19 +41,31 @@ module SchemaPlus::Views
|
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
44
|
+
# Returns the SQL definition of a given view. This is
|
45
|
+
# the literal SQL would come after 'CREATVE VIEW viewname AS ' in
|
46
|
+
# the SQL statement to create a view.
|
47
|
+
def view_definition(view_name, name = nil)
|
48
|
+
view_full_definition(view_name, name).first
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns the view type of a given view. This is either :view or :materialized
|
52
|
+
def view_type(view_name, name = nil)
|
53
|
+
view_full_definition(view_name, name).second
|
54
|
+
end
|
55
|
+
|
40
56
|
#####################################################################
|
41
57
|
#
|
42
58
|
# The functions below here are abstract; each subclass should
|
43
59
|
# define them all. Defining them here only for reference.
|
44
60
|
#
|
45
61
|
|
46
|
-
# (abstract)
|
47
|
-
def
|
62
|
+
# (abstract) Refreshes the given materialized view.
|
63
|
+
def refresh_view(view_name, name = nil) raise "Internal Error: Connection adapter didn't override abstract function"; end
|
48
64
|
|
49
|
-
# (abstract) Returns the SQL definition of a given view. This is
|
65
|
+
# (abstract) Returns the SQL definition and type of a given view. This is
|
50
66
|
# the literal SQL would come after 'CREATVE VIEW viewname AS ' in
|
51
|
-
# the SQL statement to create a view.
|
52
|
-
def
|
67
|
+
# the SQL statement to create a view. The type is either :view, or :materialized
|
68
|
+
def view_full_definition(view_name, name = nil) raise "Internal Error: Connection adapter didn't override abstract function"; end
|
53
69
|
end
|
54
70
|
end
|
55
71
|
end
|
@@ -1,18 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SchemaPlus::Views
|
2
4
|
module ActiveRecord
|
3
5
|
module ConnectionAdapters
|
4
6
|
module Mysql2Adapter
|
5
7
|
|
6
|
-
def
|
7
|
-
SchemaMonkey::Middleware::Schema::
|
8
|
-
select_all("SELECT table_name FROM information_schema.views WHERE table_schema = SCHEMA()", env.query_name).each do |row|
|
9
|
-
env.views << row["table_name"]
|
10
|
-
end
|
11
|
-
}.views
|
12
|
-
end
|
13
|
-
|
14
|
-
def view_definition(view_name, name = nil)
|
15
|
-
SchemaMonkey::Middleware::Schema::ViewDefinition.start(connection: self, view_name: view_name, query_name: name) { |env|
|
8
|
+
def view_full_definition(view_name, name = nil)
|
9
|
+
data = SchemaMonkey::Middleware::Schema::ViewDefinition.start(connection: self, view_name: view_name, query_name: name, view_type: :view) { |env|
|
16
10
|
results = select_all("SELECT view_definition, check_option FROM information_schema.views WHERE table_schema = SCHEMA() AND table_name = #{quote(view_name)}", name)
|
17
11
|
if results.any?
|
18
12
|
row = results.first
|
@@ -24,7 +18,9 @@ module SchemaPlus::Views
|
|
24
18
|
end
|
25
19
|
env.definition = sql
|
26
20
|
end
|
27
|
-
}
|
21
|
+
}
|
22
|
+
|
23
|
+
[data.definition, data.view_type]
|
28
24
|
end
|
29
25
|
|
30
26
|
end
|