activerecord-pg-format-db-structure 0.5.0 → 0.6.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 +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +15 -1
- data/lib/activerecord-pg-format-db-structure/formatter.rb +7 -1
- data/lib/activerecord-pg-format-db-structure/indenter.rb +2 -0
- data/lib/activerecord-pg-format-db-structure/preprocessors/base.rb +16 -0
- data/lib/activerecord-pg-format-db-structure/preprocessors/remove_restrict_pragmas.rb +16 -0
- data/lib/activerecord-pg-format-db-structure/railtie.rb +1 -0
- data/lib/activerecord-pg-format-db-structure/version.rb +1 -1
- data/lib/activerecord-pg-format-db-structure.rb +5 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2bcae1d47f44267453aaaf6928f5e62ddb6b49ff5bb1f045f46aea31fc7d8b05
|
|
4
|
+
data.tar.gz: 859b427c2235969091c80aeb4f43c8b396ba6a9c54d19aac393e9f3cede64471
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d47dddf87abc9126064f870ad38a730f11b871fed40c9a2e0b131d2ed4ef7f201edf01db1fc364f3fba56f891e9c3972486fc0f79d439e8f25bca422baae9681
|
|
7
|
+
data.tar.gz: 0a10698d05e4582cc676e08f40cd188e9ab7129dafe2899bd2b3db5b4e48cc89bb3fc1a10f9ad1ef25745054653b6aac826edc1246d3ea7f9f01a9b08253b027
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.6.1] - 2025-11-24
|
|
4
|
+
|
|
5
|
+
- Fix bug with aggregate filter where clause
|
|
6
|
+
|
|
7
|
+
## [0.6.0] - 2025-08-21
|
|
8
|
+
|
|
9
|
+
- Add preprocessors config that allows applying text transforms to the input before parsing
|
|
10
|
+
- Add preprocessor to remove `\restrict` and `\unrestrict` pragmas that appeared in newer versions of pg_dump
|
|
11
|
+
|
|
3
12
|
## [0.5.0] - 2025-08-04
|
|
4
13
|
|
|
5
14
|
- Upgrade pg_query to 6.1 to add support for latest mac OS version
|
data/README.md
CHANGED
|
@@ -9,6 +9,7 @@ Say good-bye to those pesky diffs you get between coworkers!
|
|
|
9
9
|
|
|
10
10
|
By default, it will:
|
|
11
11
|
|
|
12
|
+
* remove `\restrict` and `\unrestrict` pragmas
|
|
12
13
|
* Inline primary key declarations
|
|
13
14
|
* Inline SERIAL type declarations
|
|
14
15
|
* Inline table constraints
|
|
@@ -27,6 +28,8 @@ As an example, the task will transform this raw `structure.sql`:
|
|
|
27
28
|
<summary>Click to expand</summary>
|
|
28
29
|
|
|
29
30
|
```sql
|
|
31
|
+
\restrict 1234
|
|
32
|
+
|
|
30
33
|
--
|
|
31
34
|
-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: -
|
|
32
35
|
--
|
|
@@ -261,6 +264,10 @@ If you want to configure which transforms to use, you can configure the library
|
|
|
261
264
|
|
|
262
265
|
```ruby
|
|
263
266
|
Rails.application.configure do
|
|
267
|
+
config.activerecord_pg_format_db_structure.preprocessors = [
|
|
268
|
+
Preprocessors::RemoveRestrictPragmas
|
|
269
|
+
]
|
|
270
|
+
|
|
264
271
|
config.activerecord_pg_format_db_structure.transforms = [
|
|
265
272
|
ActiveRecordPgFormatDbStructure::Transforms::RemoveCommentsOnExtensions,
|
|
266
273
|
ActiveRecordPgFormatDbStructure::Transforms::RemoveDefaultsSetCommands,
|
|
@@ -271,7 +278,7 @@ Rails.application.configure do
|
|
|
271
278
|
ActiveRecordPgFormatDbStructure::Transforms::InlineConstraints,
|
|
272
279
|
ActiveRecordPgFormatDbStructure::Transforms::MoveIndicesAfterCreateTable,
|
|
273
280
|
ActiveRecordPgFormatDbStructure::Transforms::GroupAlterTableStatements,
|
|
274
|
-
ActiveRecordPgFormatDbStructure::Transforms::SortTableColumns
|
|
281
|
+
ActiveRecordPgFormatDbStructure::Transforms::SortTableColumns
|
|
275
282
|
]
|
|
276
283
|
|
|
277
284
|
config.activerecord_pg_format_db_structure.deparser = ActiveRecordPgFormatDbStructure::Deparser
|
|
@@ -287,6 +294,13 @@ structure = File.read("db/structure.sql")
|
|
|
287
294
|
formatted = ActiveRecordPgFormatDbStructure::Formatter.new.format(structure)
|
|
288
295
|
File.write("db/structure.sql", formatted)
|
|
289
296
|
```
|
|
297
|
+
## Preprocessors
|
|
298
|
+
|
|
299
|
+
### RemoveRestrictPragmas
|
|
300
|
+
|
|
301
|
+
Remove `\restrict` and `\unrestrict` pragmas that were added in newer
|
|
302
|
+
versions of `pg_dump`, since they are not valid SQL syntax and
|
|
303
|
+
therefore prevent parsing the file as SQL.
|
|
290
304
|
|
|
291
305
|
## Transformers
|
|
292
306
|
|
|
@@ -6,19 +6,25 @@ require_relative "../activerecord-pg-format-db-structure"
|
|
|
6
6
|
module ActiveRecordPgFormatDbStructure
|
|
7
7
|
# Formats & normalizes in place the given SQL string
|
|
8
8
|
class Formatter
|
|
9
|
-
attr_reader :transforms, :deparser, :statement_appender
|
|
9
|
+
attr_reader :preprocessors, :transforms, :deparser, :statement_appender
|
|
10
10
|
|
|
11
11
|
def initialize(
|
|
12
|
+
preprocessors: DEFAULT_PREPROCESSORS,
|
|
12
13
|
transforms: DEFAULT_TRANSFORMS,
|
|
13
14
|
deparser: DEFAULT_DEPARSER,
|
|
14
15
|
statement_appender: DEFAULT_STATEMENT_APPENDER
|
|
15
16
|
)
|
|
17
|
+
@preprocessors = preprocessors
|
|
16
18
|
@transforms = transforms
|
|
17
19
|
@deparser = deparser
|
|
18
20
|
@statement_appender = statement_appender
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
def format(source)
|
|
24
|
+
preprocessors.each do |preprocessor|
|
|
25
|
+
preprocessor.new(source).preprocess!
|
|
26
|
+
end
|
|
27
|
+
|
|
22
28
|
raw_statements = PgQuery.parse(source).tree.stmts
|
|
23
29
|
|
|
24
30
|
transforms.each do |transform|
|
|
@@ -125,6 +125,8 @@ module ActiveRecordPgFormatDbStructure
|
|
|
125
125
|
output.append_token
|
|
126
126
|
output.pop_scope
|
|
127
127
|
output.append_scope(type:, indent: 0)
|
|
128
|
+
in { current_token: WHERE, inside: PARENS }
|
|
129
|
+
output.append_token
|
|
128
130
|
in {
|
|
129
131
|
current_token: FROM | WHERE | GROUP | ORDER | WINDOW | HAVING | LIMIT | OFFSET | FETCH | FOR | UNION |
|
|
130
132
|
INTERSECT | EXCEPT => token_type
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module ActiveRecordPgFormatDbStructure
|
|
6
|
+
module Preprocessors
|
|
7
|
+
# Remove \restrict and \unrestrict pragmas added by newer versions
|
|
8
|
+
# of pg_dump
|
|
9
|
+
class RemoveRestrictPragmas < Base
|
|
10
|
+
def preprocess!
|
|
11
|
+
source.gsub!(/^(\\restrict .*)$/, "")
|
|
12
|
+
source.gsub!(/^(\\unrestrict .*)$/, "")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -4,6 +4,7 @@ module ActiveRecordPgFormatDbStructure
|
|
|
4
4
|
# Setup for Rails
|
|
5
5
|
class Railtie < Rails::Railtie
|
|
6
6
|
config.activerecord_pg_format_db_structure = ActiveSupport::OrderedOptions.new
|
|
7
|
+
config.activerecord_pg_format_db_structure.preprocessors = DEFAULT_PREPROCESSORS.dup
|
|
7
8
|
config.activerecord_pg_format_db_structure.transforms = DEFAULT_TRANSFORMS.dup
|
|
8
9
|
config.activerecord_pg_format_db_structure.deparser = DEFAULT_DEPARSER
|
|
9
10
|
config.activerecord_pg_format_db_structure.statement_appender = DEFAULT_STATEMENT_APPENDER
|
|
@@ -4,6 +4,7 @@ require_relative "activerecord-pg-format-db-structure/version"
|
|
|
4
4
|
|
|
5
5
|
require_relative "activerecord-pg-format-db-structure/deparser"
|
|
6
6
|
require_relative "activerecord-pg-format-db-structure/statement_appender"
|
|
7
|
+
require_relative "activerecord-pg-format-db-structure/preprocessors/remove_restrict_pragmas"
|
|
7
8
|
require_relative "activerecord-pg-format-db-structure/transforms/remove_comments_on_extensions"
|
|
8
9
|
require_relative "activerecord-pg-format-db-structure/transforms/inline_serials"
|
|
9
10
|
require_relative "activerecord-pg-format-db-structure/transforms/inline_primary_keys"
|
|
@@ -16,6 +17,10 @@ require_relative "activerecord-pg-format-db-structure/transforms/sort_schema_mig
|
|
|
16
17
|
require_relative "activerecord-pg-format-db-structure/transforms/sort_table_columns"
|
|
17
18
|
|
|
18
19
|
module ActiveRecordPgFormatDbStructure
|
|
20
|
+
DEFAULT_PREPROCESSORS = [
|
|
21
|
+
Preprocessors::RemoveRestrictPragmas
|
|
22
|
+
].freeze
|
|
23
|
+
|
|
19
24
|
DEFAULT_TRANSFORMS = [
|
|
20
25
|
Transforms::RemoveCommentsOnExtensions,
|
|
21
26
|
Transforms::RemoveDefaultsSetCommands,
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-pg-format-db-structure
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jell
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2025-
|
|
10
|
+
date: 2025-11-24 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: pg_query
|
|
@@ -42,6 +42,8 @@ files:
|
|
|
42
42
|
- lib/activerecord-pg-format-db-structure/deparser.rb
|
|
43
43
|
- lib/activerecord-pg-format-db-structure/formatter.rb
|
|
44
44
|
- lib/activerecord-pg-format-db-structure/indenter.rb
|
|
45
|
+
- lib/activerecord-pg-format-db-structure/preprocessors/base.rb
|
|
46
|
+
- lib/activerecord-pg-format-db-structure/preprocessors/remove_restrict_pragmas.rb
|
|
45
47
|
- lib/activerecord-pg-format-db-structure/railtie.rb
|
|
46
48
|
- lib/activerecord-pg-format-db-structure/statement_appender.rb
|
|
47
49
|
- lib/activerecord-pg-format-db-structure/tasks/clean_db_structure.rake
|