activerecord-pg-format-db-structure 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 476baa5e7f08de7b010ef98240bf4dc9d5f92d8c381759682dfdcbdd33ba5723
|
4
|
+
data.tar.gz: 8a9337bff151ccadbfc77cb638aca3b1097831979206cf971d4e3af4b3258c7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6c728fe8aba0d6c943ff8ac5cf16d386099ea85f4a35c101eed701b899ab3ec266b9004313007bba2d5e2567273f5aedfff857567743ea64c1a2d5bdaa1961c
|
7
|
+
data.tar.gz: 17b9b5722ac383a92969640cf30a6a68aaee073eec784cbe8545eae6f85d983a5fc7a5b2bebd66755bcf097340a8e931a4e831cc298647759f039078b51663f4
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -265,6 +265,7 @@ If you want to configure which transforms to use, you can configure the library
|
|
265
265
|
Rails.application.configure do
|
266
266
|
config.activerecord_pg_format_db_structure.transforms = [
|
267
267
|
ActiveRecordPgFormatDbStructure::Transforms::RemoveCommentsOnExtensions,
|
268
|
+
ActiveRecordPgFormatDbStructure::Transforms::RemoveDefaultsSetCommands,
|
268
269
|
ActiveRecordPgFormatDbStructure::Transforms::SortSchemaMigrations,
|
269
270
|
ActiveRecordPgFormatDbStructure::Transforms::InlinePrimaryKeys,
|
270
271
|
# ActiveRecordPgFormatDbStructure::Transforms::InlineForeignKeys,
|
@@ -295,6 +296,27 @@ File.write("db/structure.sql", formatted)
|
|
295
296
|
|
296
297
|
Remove COMMENT statement applied to extensions
|
297
298
|
|
299
|
+
### RemoveDefaultsSetCommands
|
300
|
+
|
301
|
+
Remove SET commands that apply default values to postgres settings. By default, the following defaults are handled:
|
302
|
+
|
303
|
+
```ruby
|
304
|
+
ActiveRecordPgFormatDbStructure::Transforms::RemoveDefaultsSetCommands.postgres_config_defaults = {
|
305
|
+
default_table_access_method: "heap",
|
306
|
+
default_with_oids: false,
|
307
|
+
idle_in_transaction_session_timeout: 0,
|
308
|
+
lock_timeout: 0,
|
309
|
+
statement_timeout: 0,
|
310
|
+
transaction_timeout: 0,
|
311
|
+
standard_conforming_strings: true,
|
312
|
+
xmloption: "content"
|
313
|
+
}
|
314
|
+
```
|
315
|
+
|
316
|
+
Which are the default values since Postgres 9.1. You can make changes
|
317
|
+
to the above config in case you want to handle more cases.
|
318
|
+
|
319
|
+
|
298
320
|
### SortSchemaMigrations
|
299
321
|
|
300
322
|
Sort schema_migrations inserts to be in chronological order, helps with reducing merge conflicts.
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module ActiveRecordPgFormatDbStructure
|
6
|
+
module Transforms
|
7
|
+
# Remove SET commands that apply default values to postgres settings
|
8
|
+
class RemoveDefaultsSetCommands < Base
|
9
|
+
class << self
|
10
|
+
attr_accessor :postgres_config_defaults
|
11
|
+
end
|
12
|
+
|
13
|
+
self.postgres_config_defaults = {
|
14
|
+
default_table_access_method: "heap",
|
15
|
+
default_with_oids: false,
|
16
|
+
idle_in_transaction_session_timeout: 0,
|
17
|
+
lock_timeout: 0,
|
18
|
+
statement_timeout: 0,
|
19
|
+
transaction_timeout: 0,
|
20
|
+
standard_conforming_strings: true,
|
21
|
+
xmloption: "content"
|
22
|
+
}
|
23
|
+
|
24
|
+
def transform!
|
25
|
+
raw_statements.delete_if do |raw_statement|
|
26
|
+
next unless raw_statement.stmt.to_h in variable_set_stmt: {kind: :VAR_SET_VALUE, name:, args: [{a_const:}]}
|
27
|
+
|
28
|
+
next unless self.class.postgres_config_defaults.key?(name.to_sym)
|
29
|
+
|
30
|
+
pattern = value_to_pattern(self.class.postgres_config_defaults[name.to_sym])
|
31
|
+
|
32
|
+
val_from_a_const(a_const) in ^pattern
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def value_to_pattern(value)
|
39
|
+
case value
|
40
|
+
in false
|
41
|
+
Set.new(["false", "no", "off", 0])
|
42
|
+
in true
|
43
|
+
Set.new(["true", "yes", "on", 1])
|
44
|
+
else
|
45
|
+
value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def val_from_a_const(a_const)
|
50
|
+
case a_const
|
51
|
+
in ival:
|
52
|
+
ival.fetch(:ival, 0)
|
53
|
+
in sval:
|
54
|
+
sval.fetch(:sval, "").downcase
|
55
|
+
else
|
56
|
+
a_const.values.first
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -10,12 +10,14 @@ require_relative "activerecord-pg-format-db-structure/transforms/inline_foreign_
|
|
10
10
|
require_relative "activerecord-pg-format-db-structure/transforms/move_indices_after_create_table"
|
11
11
|
require_relative "activerecord-pg-format-db-structure/transforms/inline_constraints"
|
12
12
|
require_relative "activerecord-pg-format-db-structure/transforms/group_alter_table_statements"
|
13
|
+
require_relative "activerecord-pg-format-db-structure/transforms/remove_defaults_set_commands"
|
13
14
|
require_relative "activerecord-pg-format-db-structure/transforms/sort_schema_migrations"
|
14
15
|
require_relative "activerecord-pg-format-db-structure/transforms/sort_table_columns"
|
15
16
|
|
16
17
|
module ActiveRecordPgFormatDbStructure
|
17
18
|
DEFAULT_TRANSFORMS = [
|
18
19
|
Transforms::RemoveCommentsOnExtensions,
|
20
|
+
Transforms::RemoveDefaultsSetCommands,
|
19
21
|
Transforms::SortSchemaMigrations,
|
20
22
|
Transforms::InlinePrimaryKeys,
|
21
23
|
# Transforms::InlineForeignKeys,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-pg-format-db-structure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jell
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- lib/activerecord-pg-format-db-structure/transforms/inline_serials.rb
|
53
53
|
- lib/activerecord-pg-format-db-structure/transforms/move_indices_after_create_table.rb
|
54
54
|
- lib/activerecord-pg-format-db-structure/transforms/remove_comments_on_extensions.rb
|
55
|
+
- lib/activerecord-pg-format-db-structure/transforms/remove_defaults_set_commands.rb
|
55
56
|
- lib/activerecord-pg-format-db-structure/transforms/sort_schema_migrations.rb
|
56
57
|
- lib/activerecord-pg-format-db-structure/transforms/sort_table_columns.rb
|
57
58
|
- lib/activerecord-pg-format-db-structure/version.rb
|