postgresql_adapter_extensions 1.1.0 → 1.2.0

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: db065d0487684a0647e17b2db8e5ef1f2131a6b15a7b0316d1fcd9856e46c07a
4
- data.tar.gz: bd6cb683c11d9e27c1225d5c29e638adf6f14b96b1f7c3bf1803d96944383478
3
+ metadata.gz: fedbb03323e871885e04d3799efbdbae9f5f058acc2148ed2e5005a273bedf9f
4
+ data.tar.gz: 73bfe4528be9a2a28395fe40ee40e920052058b5a1a1276fe58c4bb857e57bbf
5
5
  SHA512:
6
- metadata.gz: 986daa750a1e762d710dbda29ba587ea8c76a8894f2c7ff346b2d64dc974e4c3fe54098e9549646d584c8b8c9efb5ebe00e0581a3d00c76dc3be253e7d5af9c5
7
- data.tar.gz: 8dc3a0571ff79ce9dd058ab3c22e0876c07cd748ddc0b4c42b5f642e51869aaddc353b144be5f1feff165cbe967bacaf08f0e70dbe0828fba8ffe8fa5703c5fc
6
+ metadata.gz: e3e30ccebbbbc5eae45c6daa70d953a8479ce2fecfeedb46c5e545be614e8c5080ec48c99057d2e4fefc668e7775cb9d9bac187401e1637a47cefefd092d244b
7
+ data.tar.gz: c2c2a06aedbcaa1d1ebef70fcb61d411ad81f8d5d787b24a43a60a7f2f8c84ffab48be36531f3147a859c807edd78d094a9a689fb8be54b810ac826a827ab3e5
data/CHANGELOG.md CHANGED
@@ -1,7 +1,22 @@
1
+ ## [1.2.0](https://github.com/shivam091/postgresql_adapter_extensions/compare/v1.1.0...v1.2.0) - 2025-03-27
2
+
3
+ ### What's new
4
+
5
+ #### PostgreSQLAdapterExtensions::SequenceMethods
6
+ - Added `rename_sequence` method to rename a PostgreSQL sequences with optional IF EXISTS.
7
+
8
+ #### PostgreSQLAdapterExtensions::CommandRecorder
9
+ - Added `rename_sequence` method to record sequence rename in migrations.
10
+ - Implemented `invert_rename_sequence` to allow rollback by renaming the sequence back to its previous name.
11
+
12
+ ### Notes
13
+ - `rename_sequence` can be reversed by renaming the sequence back to its previous name.
14
+
1
15
  ## [1.1.0](https://github.com/shivam091/postgresql_adapter_extensions/compare/v1.0.0...v1.1.0) - 2025-03-21
2
16
 
3
17
  ### What's new
4
- - Extended `ActiveRecord::Migration::CommandRecorder` to support PostgreSQL sequence-related commands.
18
+
19
+ #### PostgreSQLAdapterExtensions::CommandRecorder
5
20
  - Added `create_sequence` method to record sequence creation in migrations.
6
21
  - Added `alter_sequence` method to record sequence alterations (irreversible).
7
22
  - Added `drop_sequence` method to record sequence deletions (irreversible).
@@ -12,30 +27,20 @@
12
27
  - `create_sequence` can be reversed by dropping the sequence.
13
28
  - `alter_sequence` and `drop_sequence` are irreversible operations.
14
29
 
15
- ----------
16
-
17
30
  ## [1.0.0](https://github.com/shivam091/postgresql_adapter_extensions/compare/v0.1.0...v1.0.0) - 2025-03-12
18
31
 
19
32
  ### What's new
20
33
 
21
- - Added `create_sequence` method
22
-
23
- Allows creating PostgreSQL sequences with customizable options such as start value, increment step, min/max values, caching, cycling, and ownership.
24
-
25
- - Added `alter_sequence` method
26
-
27
- Enables modifying existing PostgreSQL sequences, supporting changes to increment steps, restart values, min/max limits, caching, cycling behavior, and ownership.
34
+ #### PostgreSQLAdapterExtensions::SequenceMethods
35
+ - Added `create_sequence` method to allow creating PostgreSQL sequences with customizable options such as
36
+ start value, increment step, min/max values, caching, cycling, and ownership.
28
37
 
29
- - Added `drop_sequence` method
38
+ - Added `alter_sequence` method to enable modifying existing PostgreSQL sequences, supporting changes to
39
+ increment steps, restart values, min/max limits, caching, cycling behavior, and ownership.
30
40
 
31
- Provides functionality to remove a PostgreSQL sequence with optional IF EXISTS and CASCADE/RESTRICT behaviors to manage dependencies.
32
-
33
- ----------
41
+ - Added `drop_sequence` method to provides functionality to remove a PostgreSQL sequence with optional
42
+ IF EXISTS and CASCADE/RESTRICT behaviors to manage dependencies.
34
43
 
35
44
  ## 0.1.0 - 2025-03-11
36
45
 
37
46
  ### Initial release
38
-
39
- -----------
40
-
41
- ### Unreleased
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- postgresql_adapter_extensions (1.1.0)
4
+ postgresql_adapter_extensions (1.2.0)
5
5
  activerecord (~> 8)
6
6
  pg (~> 1.5)
7
7
 
data/README.md CHANGED
@@ -121,8 +121,8 @@ alter_sequence(:order_id_seq, cycle: false)
121
121
  alter_sequence(:order_id_seq, owned_by: "orders.id")
122
122
  ```
123
123
 
124
- This method provides flexibility in managing sequences dynamically in your Rails application,
125
- ensuring that sequence-related database behavior can be modified as needed.
124
+ This method provides flexibility in managing sequences dynamically in your Rails
125
+ application, ensuring that sequence-related database behavior can be modified as needed.
126
126
 
127
127
  ### drop_sequence
128
128
 
@@ -156,6 +156,26 @@ drop_sequence(:order_id_seq, drop_behavior: :cascade)
156
156
  drop_sequence(:order_id_seq, drop_behavior: :restrict)
157
157
  ```
158
158
 
159
+ ### rename_sequence
160
+
161
+ The `rename_sequence` method allows you to rename an existing sequence in your PostgreSQL database.
162
+
163
+ ```ruby
164
+ rename_sequence(name, options = {})
165
+ ```
166
+
167
+ **Rename a sequence:**
168
+
169
+ ```ruby
170
+ rename_sequence(:order_id_seq, to: :new_order_id_seq)
171
+ ```
172
+
173
+ **Rename a sequence only if it exists:**
174
+
175
+ ```ruby
176
+ rename_sequence(:order_id_seq, to: :new_order_id_seq, if_exists: true)
177
+ ```
178
+
159
179
  ## PostgreSQL Setup for Contributors
160
180
 
161
181
  If you're contributing to this gem and need to set up PostgreSQL for local development or testing,
@@ -77,6 +77,23 @@ module PostgreSQLAdapterExtensions
77
77
  record(:drop_sequence, args, &block)
78
78
  end
79
79
 
80
+ ##
81
+ # Records the renaming of a PostgreSQL sequence during a migration.
82
+ #
83
+ # This method is invoked when renaming a sequence in the database.
84
+ # The corresponding inverse operation will be to rename the sequence back to
85
+ # its original name during rollback.
86
+ #
87
+ # @param args [Array] Arguments required to rename the sequence (usually the old and new sequence names).
88
+ #
89
+ # @return [void]
90
+ #
91
+ # @since 1.2.0
92
+ #
93
+ def rename_sequence(*args)
94
+ record(:rename_sequence, args)
95
+ end
96
+
80
97
  private
81
98
 
82
99
  ##
@@ -117,5 +134,19 @@ module PostgreSQLAdapterExtensions
117
134
  def invert_drop_sequence(args)
118
135
  raise ActiveRecord::IrreversibleMigration, "Drop sequence is irreversible."
119
136
  end
137
+
138
+ ##
139
+ # Generates the inverse command for renaming a sequence, which renames it
140
+ # back to its original name.
141
+ #
142
+ # @param args [Array] Arguments passed to the rename_sequence method (old sequence name and new sequence name).
143
+ #
144
+ # @return [Array] An array with the inverse command `:rename_sequence` and its arguments swapped.
145
+ #
146
+ # @since 1.2.0
147
+ #
148
+ def invert_rename_sequence(args)
149
+ [:rename_sequence, [args.last[:to], to: args.first]]
150
+ end
120
151
  end
121
152
  end
@@ -175,5 +175,43 @@ module PostgreSQLAdapterExtensions
175
175
 
176
176
  execute(sql).tap { reload_type_map }
177
177
  end
178
+
179
+ ##
180
+ # Renames an existing PostgreSQL sequence.
181
+ #
182
+ # @param name [String, Symbol] The current name of the sequence.
183
+ # @param options [Hash] A hash of options for renaming the sequence.
184
+ # @option options [Boolean] :if_exists (false) Includes +IF EXISTS+ to avoid errors if the sequence does not exist.
185
+ # @option options [String, Symbol] :to The new name for the sequence.
186
+ #
187
+ # @raise [ArgumentError] If the +:to+ option is not provided.
188
+ #
189
+ # @example Rename a sequence
190
+ # rename_sequence(:order_id_seq, to: :new_order_id_seq)
191
+ #
192
+ # @example Rename a sequence only if it exists
193
+ # rename_sequence(:order_id_seq, to: :new_order_id_seq, if_exists: true)
194
+ #
195
+ # @return [void]
196
+ #
197
+ # @note Uses `ALTER SEQUENCE ... RENAME TO` SQL statement in PostgreSQL.
198
+ #
199
+ # @author {Harshal V. Ladhe}[https://shivam091.github.io/]
200
+ # @since 1.2.0
201
+ #
202
+ def rename_sequence(name, options = {})
203
+ to = options.fetch(:to) { raise ArgumentError, ":to is required" }
204
+
205
+ options = options.reverse_merge(
206
+ if_exists: false
207
+ )
208
+
209
+ sql = +"ALTER SEQUENCE"
210
+ sql << " IF EXISTS" if options[:if_exists]
211
+ sql << " #{quote_table_name(name)}"
212
+ sql << " RENAME TO #{quote_table_name(to)}"
213
+
214
+ execute(sql).tap { reload_type_map }
215
+ end
178
216
  end
179
217
  end
@@ -4,5 +4,5 @@
4
4
 
5
5
  module PostgreSQLAdapterExtensions
6
6
  # Current stable version.
7
- VERSION = "1.1.0"
7
+ VERSION = "1.2.0"
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgresql_adapter_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harshal LADHE
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-21 00:00:00.000000000 Z
11
+ date: 2025-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord