sequel-inline_schema 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 698af5cd91bac6d8f22da1c5b27c1fe9bee6de7783c50e8797e4d3b1c006b8f2
4
- data.tar.gz: 82405a67152c84ce7f7deb29136d5be145032fc835b3f91f8b46c08c85a1d007
3
+ metadata.gz: 8d62b937115b61c4fdbf02a67439eac074d97a480807c58a39fe3986ad9871b1
4
+ data.tar.gz: 179d308737aaceb2a1e3021087745c13ec5f38cd9f51baf111d0d4c59df38d14
5
5
  SHA512:
6
- metadata.gz: 76370fa88d1c87fb2b3a2537c621c1b34ac3a15fa353b12db305e33af42e8c240ffa81eb97ab1b3a573d6aee3bf9f4aabccb554920fb832aa187208c926b2307
7
- data.tar.gz: 50b13fe397a824b3d799b7d17fd4624cbb5b794ecfa01f75a4d7232a73aee349bba809f49f5a4092a9077f2630dea8f83dfa0428398b778670c3f14b668199a1
6
+ metadata.gz: 3ae55f495312766e40bdec536da6d05b2fb8830b37080c8ea983cdd2e04b98675f4fb9e18dd3e1b11420d30e4d2108b2c2bb135e96a261854da108c736dd985c
7
+ data.tar.gz: 3a8192baa58acac959e36e42fb68d2dd166a03ccc8711b4f0b8eddbd8fc69a068501e9b71efb5cf978c572893b88d248670cf5c59842fa81fa2319c728bffecf
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:
@@ -7,7 +7,7 @@ require 'sequel/plugins/inline_schema'
7
7
  module Sequel::InlineSchema
8
8
 
9
9
  # Package version
10
- VERSION = '0.3.2'
10
+ VERSION = '0.3.3'
11
11
 
12
12
  # Version control revision
13
13
  REVISION = %q$Revision$
@@ -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] => self.table_name ).
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 craete a materialized view instead of a table" do
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.2
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-11 00:00:00.000000000 Z
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