database_consistency 3.0.15 → 3.0.16
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/lib/database_consistency/version.rb +1 -1
- data/lib/database_consistency/writers/autofix/helpers/migration.rb +13 -1
- data/lib/database_consistency/writers/autofix/inconsistent_types.rb +24 -2
- data/lib/database_consistency/writers/autofix/templates/inconsistent_types.tt +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1cb0dbacf9e21959370981f0eaa7bee89164144821af616d59f7b5e90f9a0b31
|
|
4
|
+
data.tar.gz: 7f7e86c94cce08b9b1d858d8099006ac19b58aae8b5e91c4e898ed3289928afd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4caf4a0b2bfc7d5887dfb5052b2ec79a979e31589fa357a709f77819ee837a2592f858d8332c1543ce783992e4279aa16f1f53079abaf93a619cd63419d19209
|
|
7
|
+
data.tar.gz: a3adc09c9b41d1acc40dbbd393430f4db3e07f3aa0d78a5c97854971cd0ad33beaa7b73db012c6360b36adfaf11794df617db89885a2e7981ed547d3a9837563
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'time'
|
|
4
|
+
|
|
3
5
|
module DatabaseConsistency
|
|
4
6
|
module Writers
|
|
5
7
|
module Autofix
|
|
@@ -7,11 +9,21 @@ module DatabaseConsistency
|
|
|
7
9
|
module Migration # :nodoc:
|
|
8
10
|
def migration_path(name)
|
|
9
11
|
last = migration_context.migrations.last
|
|
10
|
-
version = ActiveRecord::Migration.next_migration_number(last&.version.to_i
|
|
12
|
+
version = ActiveRecord::Migration.next_migration_number(next_version_number(last&.version.to_i))
|
|
11
13
|
|
|
12
14
|
"db/migrate/#{version}_#{name.underscore}.rb"
|
|
13
15
|
end
|
|
14
16
|
|
|
17
|
+
# Adds one second to a timestamp version, so a batch of migrations keeps valid times.
|
|
18
|
+
def next_version_number(last_version)
|
|
19
|
+
return last_version + 1 unless last_version.to_s.match?(/\A\d{14}\z/)
|
|
20
|
+
|
|
21
|
+
time = Time.strptime("#{last_version} +0000", '%Y%m%d%H%M%S %z').utc
|
|
22
|
+
(time + 1).strftime('%Y%m%d%H%M%S').to_i
|
|
23
|
+
rescue ArgumentError
|
|
24
|
+
last_version + 1
|
|
25
|
+
end
|
|
26
|
+
|
|
15
27
|
def migration_path_pattern(name)
|
|
16
28
|
"db/migrate/*_#{name.underscore}.rb"
|
|
17
29
|
end
|
|
@@ -8,19 +8,41 @@ module DatabaseConsistency
|
|
|
8
8
|
{
|
|
9
9
|
table_to_change: report.table_to_change,
|
|
10
10
|
type_to_set: report.type_to_set,
|
|
11
|
-
fk_name: report.fk_name
|
|
11
|
+
fk_name: report.fk_name,
|
|
12
|
+
change_columns: change_columns
|
|
12
13
|
}
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
private
|
|
16
17
|
|
|
18
|
+
# Types such as "character varying" have characters that are not valid in a migration name.
|
|
17
19
|
def migration_name
|
|
18
|
-
"change_#{report.table_to_change}_#{
|
|
20
|
+
"change_#{report.table_to_change}_#{fk_names.join('_')}_to_#{types.join('_')}".gsub(/\W+/, '_').chomp('_')
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
def template_path
|
|
22
24
|
File.join(__dir__, 'templates', 'inconsistent_types.tt')
|
|
23
25
|
end
|
|
26
|
+
|
|
27
|
+
# Symbol literals keep names such as "billing.orders" and "character varying" valid Ruby.
|
|
28
|
+
def change_columns
|
|
29
|
+
fk_names.zip(types).reject { |_fk_name, type| type.nil? }.map do |fk_name, type|
|
|
30
|
+
" change_column #{symbol(report.table_to_change)}, #{symbol(fk_name)}, #{symbol(type)}"
|
|
31
|
+
end.join("\n")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def symbol(name)
|
|
35
|
+
name.to_sym.inspect
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Composite keys are joined with "+" and have one type for each column.
|
|
39
|
+
def fk_names
|
|
40
|
+
report.fk_name.split('+')
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def types
|
|
44
|
+
Array(report.type_to_set)
|
|
45
|
+
end
|
|
24
46
|
end
|
|
25
47
|
end
|
|
26
48
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: database_consistency
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.
|
|
4
|
+
version: 3.0.16
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Evgeniy Demin
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|