strong_migrations 1.4.1 → 1.4.2

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: a296161cd1d5cdd070c94c34bd250feb2d62cb7b5274205007bab92e50dc7d0a
4
- data.tar.gz: e95730e625ed31bb3745c0c55fddf4aa2cd6d7d99607add097d23ae1181a8b50
3
+ metadata.gz: 30cac1a5432c1dcf806208ab10dbab1fe08f757c650dd5f2af965a02638e17de
4
+ data.tar.gz: 6571d42391b5c4453cf4f529c555ddd2c91ec83625bc2b584fee3c64dfdefe96
5
5
  SHA512:
6
- metadata.gz: '03479a3996622262cad8eab0843f6fdd266e041d854ab49ced8dd334e6c9709556f6887f7708d1eeab87f98524bb558e813457f5f0cbb4c16323557353438680'
7
- data.tar.gz: 263a6238d3cc34d1211f7f6c6410248f8ee104e475f04f5e3687efb8602389ab26b12ec9155a6e782fc828e733af85b9315e9a282b5589d39f5891b46a5a83e6
6
+ metadata.gz: 69f972c7960262a4d21824ec4b0ff200b212705f3c246ecdbe5ad0ed14f3518d392b5577c7c3d7c064b024b9061352bd457580aa379d83a3c4676bb352326796
7
+ data.tar.gz: 56fe3d96e3e2e7a467bc4a2c477ca8dea7ce09418e4720119266f7442bb041bd9f5ec024b9d9f1a3213907ec3a975b530575f062d668f41b52aa66bdfbd5c8e3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.4.2 (2023-01-29)
2
+
3
+ - Added `alphabetize_schema` option
4
+
1
5
  ## 1.4.1 (2023-01-05)
2
6
 
3
7
  - Added support for multiple databases to `target_version`
data/README.md CHANGED
@@ -840,23 +840,18 @@ StrongMigrations.auto_analyze = true
840
840
 
841
841
  ## Faster Migrations
842
842
 
843
- Only dump the schema when adding a new migration. If you use Git, add to the end of your `Rakefile`:
843
+ Only dump the schema when adding a new migration. If you use Git, add to `config/environments/development.rb`:
844
844
 
845
845
  ```rb
846
- task :faster_migrations do
847
- ActiveRecord::Base.dump_schema_after_migration = Rails.env.development? &&
848
- `git status db/migrate/ --porcelain`.present?
849
- end
850
-
851
- task "db:migrate": "faster_migrations"
846
+ config.active_record.dump_schema_after_migration = `git status db/migrate/ --porcelain`.present?
852
847
  ```
853
848
 
854
849
  ## Schema Sanity
855
850
 
856
- Columns can flip order in `db/schema.rb` when you have multiple developers. One way to prevent this is to [alphabetize them](https://www.pgrs.net/2008/03/12/alphabetize-schema-rb-columns/). Add to the end of your `Rakefile`:
851
+ Columns can flip order in `db/schema.rb` when you have multiple developers. One way to prevent this is to [alphabetize them](https://www.pgrs.net/2008/03/12/alphabetize-schema-rb-columns/). Add to `config/initializers/strong_migrations.rb`:
857
852
 
858
853
  ```ruby
859
- task "db:schema:dump": "strong_migrations:alphabetize_columns"
854
+ StrongMigrations.alphabetize_schema = true
860
855
  ```
861
856
 
862
857
  ## Permissions
@@ -0,0 +1,21 @@
1
+ module StrongMigrations
2
+ module SchemaDumper
3
+ def initialize(connection, *args, **options)
4
+ return super unless StrongMigrations.alphabetize_schema
5
+
6
+ super(WrappedConnection.new(connection), *args, **options)
7
+ end
8
+ end
9
+
10
+ class WrappedConnection
11
+ delegate_missing_to :@connection
12
+
13
+ def initialize(connection)
14
+ @connection = connection
15
+ end
16
+
17
+ def columns(*args, **options)
18
+ @connection.columns(*args, **options).sort_by(&:name)
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module StrongMigrations
2
- VERSION = "1.4.1"
2
+ VERSION = "1.4.2"
3
3
  end
@@ -28,7 +28,8 @@ module StrongMigrations
28
28
  attr_accessor :auto_analyze, :start_after, :checks, :error_messages,
29
29
  :target_postgresql_version, :target_mysql_version, :target_mariadb_version,
30
30
  :enabled_checks, :lock_timeout, :statement_timeout, :check_down, :target_version,
31
- :safe_by_default, :target_sql_mode, :lock_timeout_retries, :lock_timeout_retry_delay
31
+ :safe_by_default, :target_sql_mode, :lock_timeout_retries, :lock_timeout_retry_delay,
32
+ :alphabetize_schema
32
33
  attr_writer :lock_timeout_limit
33
34
  end
34
35
  self.auto_analyze = false
@@ -38,6 +39,7 @@ module StrongMigrations
38
39
  self.checks = []
39
40
  self.safe_by_default = false
40
41
  self.check_down = false
42
+ self.alphabetize_schema = false
41
43
 
42
44
  # private
43
45
  def self.developer_env?
@@ -93,4 +95,7 @@ ActiveSupport.on_load(:active_record) do
93
95
  if defined?(ActiveRecord::Tasks::DatabaseTasks)
94
96
  ActiveRecord::Tasks::DatabaseTasks.singleton_class.prepend(StrongMigrations::DatabaseTasks)
95
97
  end
98
+
99
+ require "strong_migrations/schema_dumper"
100
+ ActiveRecord::SchemaDumper.prepend(StrongMigrations::SchemaDumper)
96
101
  end
@@ -4,11 +4,6 @@ namespace :strong_migrations do
4
4
  $stderr.puts "Dumping schema"
5
5
  ActiveRecord::Base.logger.level = Logger::INFO
6
6
 
7
- require "strong_migrations/alphabetize_columns"
8
- ActiveRecord::Base.connection.class.prepend StrongMigrations::AlphabetizeColumns
9
- if ActiveRecord::ConnectionAdapters.const_defined?('PostGISAdapter')
10
- ActiveRecord::ConnectionAdapters::PostGISAdapter.prepend StrongMigrations::AlphabetizeColumns
11
- end
12
- ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend StrongMigrations::AlphabetizeColumns
7
+ StrongMigrations.alphabetize_schema = true
13
8
  end
14
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strong_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-01-05 00:00:00.000000000 Z
13
+ date: 2023-01-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -45,7 +45,6 @@ files:
45
45
  - lib/strong_migrations/adapters/mariadb_adapter.rb
46
46
  - lib/strong_migrations/adapters/mysql_adapter.rb
47
47
  - lib/strong_migrations/adapters/postgresql_adapter.rb
48
- - lib/strong_migrations/alphabetize_columns.rb
49
48
  - lib/strong_migrations/checker.rb
50
49
  - lib/strong_migrations/checks.rb
51
50
  - lib/strong_migrations/database_tasks.rb
@@ -54,6 +53,7 @@ files:
54
53
  - lib/strong_migrations/migrator.rb
55
54
  - lib/strong_migrations/railtie.rb
56
55
  - lib/strong_migrations/safe_methods.rb
56
+ - lib/strong_migrations/schema_dumper.rb
57
57
  - lib/strong_migrations/version.rb
58
58
  - lib/tasks/strong_migrations.rake
59
59
  homepage: https://github.com/ankane/strong_migrations
@@ -1,11 +0,0 @@
1
- module StrongMigrations
2
- module AlphabetizeColumns
3
- def columns(*args)
4
- super.sort_by(&:name)
5
- end
6
-
7
- def extensions(*args)
8
- super.sort
9
- end
10
- end
11
- end