ae_check_migrations_load_silently 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b76540091b20bf219a815f5ee7dde9272d4f8029435a36c0b3fd7294131e671f
4
+ data.tar.gz: db2f412966f0b86194aff16b74d7e678a1dd48194de28cc1480c1fc27a9e26c5
5
+ SHA512:
6
+ metadata.gz: 63ed8730d210bf7a9f6666be23071767f21de6dbe0805f5d908bec64178ba0418edea1e33d0c107c7ff7aefe83f68955bd12dee6b0c236842098b3b8ab757e46
7
+ data.tar.gz: b0afb5b34055d1b08ee1a19ebad5ab67214cd831037e9d57770b3611998124c1cb7b3393206002341eca3f8420c34aac86e23291954673b54f2da957d666a00c
@@ -0,0 +1,55 @@
1
+
2
+ require 'active_record'
3
+
4
+ class AeCheckMigrationsLoadSilently
5
+ class << self
6
+
7
+ def run
8
+ before_checksums = get_database_checksums
9
+ load_all_migrations
10
+ after_checksums = get_database_checksums
11
+
12
+ tables_modified = (
13
+ (before_checksums - after_checksums).map(&:first) +
14
+ (after_checksums - before_checksums).map(&:first)
15
+ ).uniq
16
+
17
+ if tables_modified.present?
18
+ error_message = <<~MSG
19
+ The following tables were modified when the migration classes were
20
+ loaded. This is not compatable with our release process. This is likely
21
+ because the migration has database modifiying code on the
22
+ class rather than inside a method.
23
+
24
+ #{tables_modified.sort.join("\n")}
25
+ MSG
26
+
27
+ flunk error_message
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def get_database_checksums
34
+ tables_sql = ActiveRecord::Base.connection.tables.sort.join(", ")
35
+ checksum_sql = "CHECKSUM TABLE #{tables_sql}"
36
+ ActiveRecord::Base.connection.execute(checksum_sql).to_a
37
+ end
38
+
39
+ def load_all_migrations
40
+ migrations_to_process = Dir['db/migrate/20*.rb']
41
+ migrations_to_process.each do |migration|
42
+ begin
43
+ load migration
44
+ rescue StandardError => e
45
+ msg = <<~MSG
46
+ #{self.class.name}: #{migration} failed to load. This is likely because the migration has code that is defined
47
+ on the top level class, instead of in a method.
48
+ #{e.message}
49
+ MSG
50
+ flunk msg
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ae_check_migrations_load_silently
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Appfolio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Check migrations do not affect database on load
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/ae_check_migrations_load_silently.rb
34
+ homepage:
35
+ licenses: []
36
+ metadata: {}
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.0.8
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: Check migrations do not affect database on load
56
+ test_files: []