updateable_views_inheritance 1.4.4 → 1.4.5
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8712364c9596c4bf050aeac6f2c6471d180d9a4fccec891b4e1b65e3d80d6d9b
|
4
|
+
data.tar.gz: 6b5fa6ac3a504c659a22da83717099976848d8e0499282daa6bf276b1b4766bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 735b84529fa5855434e025cf1f22015af66f00d098284f9492b2b06529872478b478732f44b72442e4c30660b7b4a919a4bfe99cda357967a2d00af2fb915716
|
7
|
+
data.tar.gz: ced8b499fe12b8451f0c8c1caf00aacb2cea83e2858279cf3c126e8241fbf3fc038d80f1256ad817762963ed6701c79bcfc2b5ff15c0abdeaf794ccbfeb35dbc
|
data/CHANGELOG.md
CHANGED
@@ -305,7 +305,7 @@ module ActiveRecord #:nodoc:
|
|
305
305
|
def do_create_child_view(parent_table, parent_columns, parent_pk, child_view, child_columns, child_pk, child_table)
|
306
306
|
view_columns = parent_columns + child_columns
|
307
307
|
execute(<<~SQL)
|
308
|
-
CREATE OR REPLACE VIEW #{
|
308
|
+
CREATE OR REPLACE VIEW #{quote_table_name(child_view)} AS (
|
309
309
|
SELECT parent.#{parent_pk},
|
310
310
|
#{ view_columns.map { |col| quote_column_name(col) }.join(",") }
|
311
311
|
FROM #{parent_table} parent
|
@@ -322,7 +322,7 @@ module ActiveRecord #:nodoc:
|
|
322
322
|
# Setting the sequence to its value (explicitly supplied or the default) covers both cases.
|
323
323
|
execute(<<~SQL)
|
324
324
|
CREATE OR REPLACE RULE #{quote_column_name("#{child_view}_insert")} AS
|
325
|
-
ON INSERT TO #{
|
325
|
+
ON INSERT TO #{quote_table_name(child_view)} DO INSTEAD (
|
326
326
|
INSERT INTO #{parent_table}
|
327
327
|
( #{ [parent_pk, parent_columns].flatten.map { |col| quote_column_name(col) }.join(", ") } )
|
328
328
|
VALUES( DEFAULT #{ parent_columns.empty? ? '' : ' ,' + parent_columns.collect{ |col| "NEW.#{quote_column_name(col)}" }.join(", ") } ) ;
|
@@ -336,14 +336,14 @@ module ActiveRecord #:nodoc:
|
|
336
336
|
# delete
|
337
337
|
execute(<<~SQL)
|
338
338
|
CREATE OR REPLACE RULE #{quote_column_name("#{child_view}_delete")} AS
|
339
|
-
ON DELETE TO #{
|
339
|
+
ON DELETE TO #{quote_table_name(child_view)} DO INSTEAD
|
340
340
|
DELETE FROM #{parent_table} WHERE #{parent_pk} = OLD.#{parent_pk}
|
341
341
|
SQL
|
342
342
|
|
343
343
|
# update
|
344
344
|
execute(<<~SQL)
|
345
345
|
CREATE OR REPLACE RULE #{quote_column_name("#{child_view}_update")} AS
|
346
|
-
ON UPDATE TO #{
|
346
|
+
ON UPDATE TO #{quote_table_name(child_view)} DO INSTEAD (
|
347
347
|
#{ if parent_columns.empty?
|
348
348
|
''
|
349
349
|
else
|
@@ -364,9 +364,9 @@ module ActiveRecord #:nodoc:
|
|
364
364
|
|
365
365
|
def insert_returning_clause(parent_pk, child_pk, child_view)
|
366
366
|
columns_cast_to_null = columns(child_view)
|
367
|
-
|
368
|
-
|
369
|
-
|
367
|
+
.reject { |c| c.name == parent_pk }
|
368
|
+
.map { |c| "CAST (NULL AS #{c.sql_type})" }
|
369
|
+
.join(", ")
|
370
370
|
"RETURNING #{child_pk}, #{columns_cast_to_null}"
|
371
371
|
end
|
372
372
|
|
data/test/schema_test.rb
CHANGED
@@ -184,22 +184,22 @@ class UpdateableViewsInheritanceSchemaTest < ActiveSupport::TestCase
|
|
184
184
|
t.column :interrail_max_speed, :integer
|
185
185
|
t.column :type, :string
|
186
186
|
end
|
187
|
-
create_child('interrail.steam_locomotives', :
|
188
|
-
t.decimal :interrail_water_consumption, :
|
189
|
-
t.decimal :interrail_coal_consumption, :
|
187
|
+
create_child('interrail.steam_locomotives', parent: 'interrail.locomotives') do |t|
|
188
|
+
t.decimal :interrail_water_consumption, precision: 6, scale: 2
|
189
|
+
t.decimal :interrail_coal_consumption, precision: 6, scale: 2
|
190
190
|
end
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
194
194
|
def test_create_child_in_schema
|
195
195
|
CreateChildInSchema.up
|
196
|
-
assert_equal %w
|
196
|
+
assert_equal %w[id
|
197
197
|
interrail_coal_consumption
|
198
198
|
interrail_max_speed
|
199
199
|
interrail_name
|
200
200
|
interrail_water_consumption
|
201
|
-
type
|
202
|
-
@connection.columns('interrail.steam_locomotives').map
|
201
|
+
type],
|
202
|
+
@connection.columns('interrail.steam_locomotives').map(&:name).sort
|
203
203
|
end
|
204
204
|
|
205
205
|
class ChangeTablesInTwoInheritanceChains < ActiveRecord::Migration
|