sequel-inline_schema 0.3.2 → 0.3.3
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
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.md +8 -0
- data/lib/sequel/inline_schema.rb +1 -1
- data/lib/sequel/plugins/inline_schema.rb +9 -5
- data/spec/sequel/plugins/inline_schema_spec.rb +17 -1
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d62b937115b61c4fdbf02a67439eac074d97a480807c58a39fe3986ad9871b1
|
4
|
+
data.tar.gz: 179d308737aaceb2a1e3021087745c13ec5f38cd9f51baf111d0d4c59df38d14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ae55f495312766e40bdec536da6d05b2fb8830b37080c8ea983cdd2e04b98675f4fb9e18dd3e1b11420d30e4d2108b2c2bb135e96a261854da108c736dd985c
|
7
|
+
data.tar.gz: 3a8192baa58acac959e36e42fb68d2dd166a03ccc8711b4f0b8eddbd8fc69a068501e9b71efb5cf978c572893b88d248670cf5c59842fa81fa2319c728bffecf
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/History.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
---
|
4
4
|
|
5
|
+
## v0.3.3 [2020-02-24] Michael Granger <ged@faeriemud.org>
|
6
|
+
|
7
|
+
Bugfixes:
|
8
|
+
|
9
|
+
- Allow options to be passed through #drop_table
|
10
|
+
- Fix view_exists? query for schema-qualified table names
|
11
|
+
|
12
|
+
|
5
13
|
## v0.3.2 [2020-02-11] Michael Granger <ged@faeriemud.org>
|
6
14
|
|
7
15
|
Bugfixes:
|
data/lib/sequel/inline_schema.rb
CHANGED
@@ -175,16 +175,16 @@ module Sequel::Plugins::InlineSchema
|
|
175
175
|
|
176
176
|
|
177
177
|
### Drops table. If the table doesn't exist, this will probably raise an error.
|
178
|
-
def drop_table
|
178
|
+
def drop_table( opts={} )
|
179
179
|
self.before_drop_table
|
180
|
-
self.db.drop_table( self.table_name )
|
180
|
+
self.db.drop_table( self.table_name, opts )
|
181
181
|
self.after_drop_table
|
182
182
|
end
|
183
183
|
|
184
184
|
|
185
185
|
### Drops table if it already exists, do nothing.
|
186
|
-
def drop_table?
|
187
|
-
self.drop_table if self.table_exists?
|
186
|
+
def drop_table?( opts={} )
|
187
|
+
self.drop_table( opts ) if self.table_exists?
|
188
188
|
end
|
189
189
|
|
190
190
|
|
@@ -253,17 +253,21 @@ module Sequel::Plugins::InlineSchema
|
|
253
253
|
|
254
254
|
|
255
255
|
### Returns true if the view associated with this model exists, false otherwise.
|
256
|
+
### :FIXME: This is PostgreSQL-specific, but there doesn't appear to be any
|
257
|
+
### cross-driver way to check for a view.
|
256
258
|
def view_exists?
|
257
259
|
# Make shortcuts for fully-qualified names
|
258
260
|
class_table = Sequel[:pg_catalog][:pg_class].as( :c )
|
259
261
|
ns_table = Sequel[:pg_catalog][:pg_namespace].as( :n )
|
260
262
|
is_visible = Sequel[:pg_catalog][:pg_table_is_visible]
|
261
263
|
|
264
|
+
_, table, _ = Sequel.split_symbol( self.table_name )
|
265
|
+
|
262
266
|
ds = db[ class_table ].
|
263
267
|
join( ns_table, oid: :relnamespace )
|
264
268
|
ds = ds.where( Sequel[:c][:relkind] => ['v', 'm'] ).
|
265
269
|
exclude( Sequel[:n][:nspname] => /^pg_toast/ ).
|
266
|
-
where( Sequel[:c][:relname] =>
|
270
|
+
where( Sequel[:c][:relname] => table.to_s ).
|
267
271
|
where( Sequel.function(is_visible, Sequel[:c][:oid]) )
|
268
272
|
|
269
273
|
return ds.count == 1
|
@@ -201,6 +201,11 @@ describe Sequel::Plugins::InlineSchema do
|
|
201
201
|
end
|
202
202
|
|
203
203
|
|
204
|
+
it "allows a model to pass options when dropping its table" do
|
205
|
+
model_class.drop_table( cascade: true )
|
206
|
+
expect( db.sqls ).to include( %{DROP TABLE "#{table}" CASCADE} )
|
207
|
+
end
|
208
|
+
|
204
209
|
|
205
210
|
it "allows a model to create a view instead of a table" do
|
206
211
|
db.fetch = fake_db_fetcher
|
@@ -214,7 +219,7 @@ describe Sequel::Plugins::InlineSchema do
|
|
214
219
|
end
|
215
220
|
|
216
221
|
|
217
|
-
it "allows a model to
|
222
|
+
it "allows a model to create a materialized view instead of a table" do
|
218
223
|
db.fetch = fake_db_fetcher
|
219
224
|
db.sqls.clear
|
220
225
|
|
@@ -227,6 +232,17 @@ describe Sequel::Plugins::InlineSchema do
|
|
227
232
|
end
|
228
233
|
|
229
234
|
|
235
|
+
it "allows a model to determine whether its view exists or not" do
|
236
|
+
view_class.view_exists?
|
237
|
+
statements = db.sqls.dup
|
238
|
+
|
239
|
+
expect( statements.last ).to include( %{WHERE (("c"."relkind" IN ('v', 'm'))} )
|
240
|
+
expect( statements.last ).to include(
|
241
|
+
%{("c"."relname" = '#{view}') AND "pg_catalog"."pg_table_is_visible"("c"."oid")) LIMIT 1}
|
242
|
+
)
|
243
|
+
end
|
244
|
+
|
245
|
+
|
230
246
|
it "allows a model to drop its view" do
|
231
247
|
db.fetch = fake_db_fetcher
|
232
248
|
db.sqls.clear
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-inline_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Granger
|
@@ -34,7 +34,7 @@ cert_chain:
|
|
34
34
|
jBZSA+N+xUTgUWpXjjwsLZjzJkhWATJWq+krNXcqpwXo6HsjmdUxoFMt63RBb+sI
|
35
35
|
XrxOxp8o0uOkU7FdLSGsyqJ2LzsR4obN
|
36
36
|
-----END CERTIFICATE-----
|
37
|
-
date: 2020-02-
|
37
|
+
date: 2020-02-24 00:00:00.000000000 Z
|
38
38
|
dependencies:
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: sequel
|
metadata.gz.sig
CHANGED
Binary file
|