Skip to content

Commit 0e82912

Browse files
committed
Remove preprocessor, update pitch in readme
1 parent 5f9831d commit 0e82912

File tree

8 files changed

+14
-100
lines changed

8 files changed

+14
-100
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## [Unreleased]
22

3+
- Remove preprocessors (no longer relevant now that we don't reuse the source string in the output)
4+
35
## [0.1.5] - 2025-02-08
46

57
- Sort table columns

README.md

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ReifyAB/activerecord-pg-format-db-structure/main.yml)
44

55

6-
Automatically cleans up your `structure.sql` file after each rails migration.
6+
Automatically cleans up your PostgreSQL `structure.sql` file after each rails migration.
7+
8+
Say good-bye to small those small diffs you get between coworkers!
79

810
By default, it will:
911

@@ -14,9 +16,11 @@ By default, it will:
1416
* Group `ALTER TABLE` statements into a single statement per table
1517
* Sorts table column declarations (primary key / foreign keys / data / timestamp / constraints)
1618
* Sorts `schema_migrations` inserts
17-
* Removes unnecessary whitespace
19+
* Format and indent the entire file consistently
20+
21+
It can also optionally inline foreign key declarations (see below).
1822

19-
The task will transform this raw `structure.sql`:
23+
As an example, the task will transform this raw `structure.sql`:
2024

2125
<details>
2226

@@ -184,7 +188,7 @@ INSERT INTO "schema_migrations" (version) VALUES
184188
```
185189
</details>
186190

187-
into this much more compact and normalized version:
191+
into this normalize (and much more compatch & readable) version:
188192

189193
```sql
190194

@@ -230,8 +234,9 @@ INSERT INTO schema_migrations (version) VALUES
230234
;
231235
```
232236

233-
which is a lot more compact, easier to read, and reduces the risk of
234-
getting random diffs between machines after each migration.
237+
The goal is to make your `structure.sql` file easier to read and to
238+
reduce the risk of getting random diffs between machines after each
239+
migration.
235240

236241
Those transformations are made by manipulating the SQL AST directly
237242
using [pg_query](https://github.com/pganalyze/pg_query), and each
@@ -258,10 +263,6 @@ If you want to configure which transforms to use, you can configure the library
258263

259264
```ruby
260265
Rails.application.configure do
261-
config.activerecord_pg_format_db_structure.preprocessors = [
262-
ActiveRecordPgFormatDbStructure::Preprocessors::RemoveWhitespaces
263-
]
264-
265266
config.activerecord_pg_format_db_structure.transforms = [
266267
ActiveRecordPgFormatDbStructure::Transforms::RemoveCommentsOnExtensions,
267268
ActiveRecordPgFormatDbStructure::Transforms::SortSchemaMigrations,
@@ -288,12 +289,6 @@ formatted = ActiveRecordPgFormatDbStructure::Formatter.new.format(structure)
288289
File.write("db/structure.sql", formatted)
289290
```
290291

291-
## Preprocessors
292-
293-
### RemoveWhitespaces
294-
295-
Remove unnecessary comment, whitespase and empty lines.
296-
297292
## Transformers
298293

299294
### RemoveCommentsOnExtensions

lib/activerecord-pg-format-db-structure.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require_relative "activerecord-pg-format-db-structure/version"
44

55
require_relative "activerecord-pg-format-db-structure/deparser"
6-
require_relative "activerecord-pg-format-db-structure/preprocessors/remove_whitespaces"
76
require_relative "activerecord-pg-format-db-structure/transforms/remove_comments_on_extensions"
87
require_relative "activerecord-pg-format-db-structure/transforms/inline_serials"
98
require_relative "activerecord-pg-format-db-structure/transforms/inline_primary_keys"
@@ -15,10 +14,6 @@
1514
require_relative "activerecord-pg-format-db-structure/transforms/sort_table_columns"
1615

1716
module ActiveRecordPgFormatDbStructure
18-
DEFAULT_PREPROCESSORS = [
19-
Preprocessors::RemoveWhitespaces
20-
].freeze
21-
2217
DEFAULT_TRANSFORMS = [
2318
Transforms::RemoveCommentsOnExtensions,
2419
Transforms::SortSchemaMigrations,

lib/activerecord-pg-format-db-structure/formatter.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,17 @@
66
module ActiveRecordPgFormatDbStructure
77
# Formats & normalizes in place the given SQL string
88
class Formatter
9-
attr_reader :preprocessors, :transforms, :deparser
9+
attr_reader :transforms, :deparser
1010

1111
def initialize(
12-
preprocessors: DEFAULT_PREPROCESSORS,
1312
transforms: DEFAULT_TRANSFORMS,
1413
deparser: DEFAULT_DEPARSER
1514
)
16-
@preprocessors = preprocessors
1715
@transforms = transforms
1816
@deparser = deparser
1917
end
2018

2119
def format(source)
22-
preprocessors.each do |preprocessor|
23-
preprocessor.new(source).preprocess!
24-
end
25-
2620
raw_statements = PgQuery.parse(source).tree.stmts
2721

2822
transforms.each do |transform|

lib/activerecord-pg-format-db-structure/preprocessors/remove_whitespaces.rb

Lines changed: 0 additions & 27 deletions
This file was deleted.

lib/activerecord-pg-format-db-structure/railtie.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module ActiveRecordPgFormatDbStructure
44
# Setup for Rails
55
class Railtie < Rails::Railtie
66
config.activerecord_pg_format_db_structure = ActiveSupport::OrderedOptions.new
7-
config.activerecord_pg_format_db_structure.preprocessors = DEFAULT_PREPROCESSORS.dup
87
config.activerecord_pg_format_db_structure.transforms = DEFAULT_TRANSFORMS.dup
98
config.activerecord_pg_format_db_structure.deparser = DEFAULT_DEPARSER
109

spec/activerecord-pg-format-db-structure/deparser_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
RSpec.describe ActiveRecordPgFormatDbStructure::Deparser do
44
let(:formatter) do
55
ActiveRecordPgFormatDbStructure::Formatter.new(
6-
preprocessors: [],
76
transforms: [],
87
deparser: described_class
98
)

spec/activerecord-pg-format-db-structure/preprocessors/remove_whitespaces_spec.rb

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)