activerecord-pg-extensions 0.7.0 → 0.7.1
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: d50633abe33747fede3503dad765972ffd7abd47f6aa3da2e955981820aff2ee
|
|
4
|
+
data.tar.gz: ea51e816b3bb0c969e5ee2a6626206e9bd8b429ad4589caac620eaa3ca7d31b6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fa97981e3721d0cc3d90697254cf89cd21666976ddeacc2e774112d3d02d0f74eaaf30fef33532965b2d8243e6f2ca2806f548d404987677cd02ba7192dbcb9f
|
|
7
|
+
data.tar.gz: 93243bece3aceba1d70646dc7a34b5b8902d6673029b31788aee0beb836b00573cc50c142501ccd4842097276ddfb217eea3ce0d9209ea4eedc48cbecba73654
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveRecord
|
|
4
|
+
module PGExtensions
|
|
5
|
+
# adds support for reverting migration methods added by this gem
|
|
6
|
+
module CommandRecorder
|
|
7
|
+
def rename_constraint(table_name, old_name, new_name, **options)
|
|
8
|
+
record(:rename_constraint, [table_name, old_name, new_name, options])
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def invert_rename_constraint(args)
|
|
12
|
+
table_name, old_name, new_name, options = args
|
|
13
|
+
options ||= {}
|
|
14
|
+
# flag the trailing hash as keyword arguments so it's replayed as
|
|
15
|
+
# `rename_constraint(..., if_exists:)` rather than a positional hash
|
|
16
|
+
[:rename_constraint, [table_name, new_name, old_name, Hash.ruby2_keywords_hash(options)]]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -27,6 +27,17 @@ module ActiveRecord
|
|
|
27
27
|
set_constraints(:immediate, *constraints)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
# renames a constraint on a table
|
|
31
|
+
# see https://www.postgresql.org/docs/current/sql-altertable.html
|
|
32
|
+
def rename_constraint(table_name, old_name, new_name, if_exists: false)
|
|
33
|
+
return if if_exists && !constraint_exists?(table_name, name: old_name)
|
|
34
|
+
|
|
35
|
+
execute(<<~SQL.squish)
|
|
36
|
+
ALTER TABLE #{quote_table_name(table_name)}
|
|
37
|
+
RENAME CONSTRAINT #{quote_column_name(old_name)} TO #{quote_column_name(new_name)}
|
|
38
|
+
SQL
|
|
39
|
+
end
|
|
40
|
+
|
|
30
41
|
# see https://www.postgresql.org/docs/current/sql-altertable.html#SQL-CREATETABLE-REPLICA-IDENTITY
|
|
31
42
|
def set_replica_identity(table, identity = :default)
|
|
32
43
|
identity_clause = case identity
|
|
@@ -285,6 +296,19 @@ module ActiveRecord
|
|
|
285
296
|
super
|
|
286
297
|
end
|
|
287
298
|
|
|
299
|
+
def constraint_exists?(table_name, name:)
|
|
300
|
+
scope = quoted_scope(name)
|
|
301
|
+
table = quoted_scope(table_name)
|
|
302
|
+
select_value(<<~SQL, "SCHEMA") == 1
|
|
303
|
+
SELECT 1 FROM pg_constraint
|
|
304
|
+
INNER JOIN pg_class ON pg_class.oid = pg_constraint.conrelid
|
|
305
|
+
INNER JOIN pg_namespace ON pg_namespace.oid = pg_constraint.connamespace
|
|
306
|
+
WHERE pg_constraint.conname = #{scope[:name]}
|
|
307
|
+
AND pg_class.relname = #{table[:name]}
|
|
308
|
+
AND pg_namespace.nspname = #{scope[:schema]}
|
|
309
|
+
SQL
|
|
310
|
+
end
|
|
311
|
+
|
|
288
312
|
def pre_pg10_wal_function_name(func)
|
|
289
313
|
return func if postgresql_version >= 100_000
|
|
290
314
|
|
|
@@ -10,9 +10,11 @@ module ActiveRecord
|
|
|
10
10
|
ActiveSupport.on_load(:active_record) do
|
|
11
11
|
require "active_record/pg_extensions/errors"
|
|
12
12
|
require "active_record/pg_extensions/postgresql_adapter"
|
|
13
|
+
require "active_record/pg_extensions/command_recorder"
|
|
13
14
|
require "active_record/pg_extensions/transaction"
|
|
14
15
|
|
|
15
16
|
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(PostgreSQLAdapter)
|
|
17
|
+
::ActiveRecord::Migration::CommandRecorder.include(CommandRecorder)
|
|
16
18
|
::ActiveRecord::ConnectionAdapters::NullTransaction.prepend(NullTransaction)
|
|
17
19
|
::ActiveRecord::ConnectionAdapters::Transaction.prepend(Transaction)
|
|
18
20
|
# if they've already require 'all', then inject now
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-pg-extensions
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.7.
|
|
4
|
+
version: 0.7.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Cody Cutrer
|
|
@@ -61,6 +61,7 @@ files:
|
|
|
61
61
|
- README.md
|
|
62
62
|
- lib/active_record/pg_extensions.rb
|
|
63
63
|
- lib/active_record/pg_extensions/all.rb
|
|
64
|
+
- lib/active_record/pg_extensions/command_recorder.rb
|
|
64
65
|
- lib/active_record/pg_extensions/errors.rb
|
|
65
66
|
- lib/active_record/pg_extensions/extension.rb
|
|
66
67
|
- lib/active_record/pg_extensions/pessimistic_migrations.rb
|
|
@@ -89,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
89
90
|
- !ruby/object:Gem::Version
|
|
90
91
|
version: '0'
|
|
91
92
|
requirements: []
|
|
92
|
-
rubygems_version: 4.0.
|
|
93
|
+
rubygems_version: 4.0.16
|
|
93
94
|
specification_version: 4
|
|
94
95
|
summary: Several extensions to ActiveRecord's PostgreSQLAdapter.
|
|
95
96
|
test_files: []
|