migration_tools 1.8.0 → 1.10.0
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/migration_tools/migration_extension.rb +2 -3
- data/lib/migration_tools/tasks.rb +42 -22
- data/lib/migration_tools.rb +7 -7
- metadata +23 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2862f79e61fa0bab55c9049a392fb4d975e8ad0d70f5a620854b82088dfc2304
|
4
|
+
data.tar.gz: 3db8c3c265bed5358e8da27c4c8eb5570f265341144bf6327a4e5a85d99ad732
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 161c3458ae787335bb1e8e02c2e312f6a93acfc604b9da3f20cf96d74e4f3cbfd083dfc50ca78f4ceabe448bbc52fdc90341e5b8e73149e6fb5fa78aff341f0e
|
7
|
+
data.tar.gz: 87f8608c1ba2bd9fc3125fd081be959498eb68d3919fbb741c85727174b6837305e7104d739e3de067b2e9c073d7abef0c22614b8ebffd82ef63f017a23a541f
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module MigrationTools
|
2
2
|
module MigrationExtension
|
3
|
-
|
4
3
|
attr_accessor :migration_group
|
5
4
|
|
6
5
|
def group(arg = nil)
|
7
6
|
unless MigrationTools::MIGRATION_GROUPS.member?(arg.to_s)
|
8
|
-
raise "Invalid group \"#{arg
|
7
|
+
raise "Invalid group \"#{arg}\" - valid groups are #{MigrationTools::MIGRATION_GROUPS.inspect}"
|
9
8
|
end
|
10
9
|
|
11
10
|
self.migration_group = arg.to_s
|
@@ -31,4 +30,4 @@ ActiveRecord::Migration.class_eval do
|
|
31
30
|
self.class.migration_group
|
32
31
|
end
|
33
32
|
end
|
34
|
-
ActiveRecord::MigrationProxy.delegate :migration_group, :
|
33
|
+
ActiveRecord::MigrationProxy.delegate :migration_group, to: :migration
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rake"
|
2
|
+
require "rake/tasklib"
|
3
3
|
|
4
4
|
module MigrationTools
|
5
5
|
class Tasks < ::Rake::TaskLib
|
@@ -12,7 +12,7 @@ module MigrationTools
|
|
12
12
|
def group
|
13
13
|
return @group if defined?(@group) && @group
|
14
14
|
|
15
|
-
@group = ENV[
|
15
|
+
@group = ENV["GROUP"].to_s
|
16
16
|
raise "Invalid group \"#{@group}\"" if !@group.empty? && !MIGRATION_GROUPS.member?(@group)
|
17
17
|
@group
|
18
18
|
end
|
@@ -20,7 +20,7 @@ module MigrationTools
|
|
20
20
|
def group=(group)
|
21
21
|
@group = nil
|
22
22
|
@pending_migrations = nil
|
23
|
-
ENV[
|
23
|
+
ENV["GROUP"] = group
|
24
24
|
end
|
25
25
|
|
26
26
|
def migrations_paths
|
@@ -28,23 +28,37 @@ module MigrationTools
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def migrator(target_version = nil)
|
31
|
-
if ActiveRecord::VERSION::MAJOR
|
31
|
+
if ActiveRecord::VERSION::MAJOR == 7 && ActiveRecord::VERSION::MINOR == 1
|
32
32
|
migrate_up(ActiveRecord::MigrationContext.new(
|
33
33
|
migrations_paths,
|
34
|
-
ActiveRecord::
|
34
|
+
ActiveRecord::Base.connection.schema_migration
|
35
|
+
).migrations, target_version)
|
36
|
+
elsif ActiveRecord.gem_version >= Gem::Version.new("7.2")
|
37
|
+
migrate_up(ActiveRecord::MigrationContext.new(
|
38
|
+
migrations_paths,
|
39
|
+
ActiveRecord::Base.connection_pool.schema_migration
|
35
40
|
).migrations, target_version)
|
36
|
-
elsif ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR == 2
|
37
|
-
migrate_up(ActiveRecord::MigrationContext.new(migrations_paths).migrations, target_version)
|
38
41
|
else
|
39
|
-
migrate_up(ActiveRecord::
|
42
|
+
migrate_up(ActiveRecord::MigrationContext.new(
|
43
|
+
migrations_paths,
|
44
|
+
ActiveRecord::SchemaMigration
|
45
|
+
).migrations, target_version)
|
40
46
|
end
|
41
47
|
end
|
42
48
|
|
43
49
|
def migrate_up(migrations, target_version)
|
44
|
-
if ActiveRecord::VERSION::MAJOR
|
45
|
-
ActiveRecord::Migrator.new(:up, migrations,
|
50
|
+
if ActiveRecord::VERSION::MAJOR == 7 && ActiveRecord::VERSION::MINOR == 1
|
51
|
+
ActiveRecord::Migrator.new(:up, migrations,
|
52
|
+
ActiveRecord::Base.connection.schema_migration,
|
53
|
+
ActiveRecord::Base.connection.internal_metadata,
|
54
|
+
target_version)
|
55
|
+
elsif ActiveRecord.gem_version >= Gem::Version.new("7.2")
|
56
|
+
ActiveRecord::Migrator.new(:up, migrations,
|
57
|
+
ActiveRecord::Base.connection_pool.schema_migration,
|
58
|
+
ActiveRecord::Base.connection_pool.internal_metadata,
|
59
|
+
target_version)
|
46
60
|
else
|
47
|
-
ActiveRecord::Migrator.new(:up, migrations, target_version)
|
61
|
+
ActiveRecord::Migrator.new(:up, migrations, ActiveRecord::SchemaMigration, target_version)
|
48
62
|
end
|
49
63
|
end
|
50
64
|
|
@@ -59,14 +73,14 @@ module MigrationTools
|
|
59
73
|
def define_migrate_list
|
60
74
|
namespace :db do
|
61
75
|
namespace :migrate do
|
62
|
-
desc
|
63
|
-
task :
|
76
|
+
desc "Lists pending migrations"
|
77
|
+
task list: :environment do
|
64
78
|
if pending_migrations.empty?
|
65
79
|
notify "Your database schema is up to date", group
|
66
80
|
else
|
67
81
|
notify "You have #{pending_migrations.size} pending migrations", group
|
68
82
|
pending_migrations.each do |migration|
|
69
|
-
notify
|
83
|
+
notify " %4d %s %s" % [migration.version, migration.migration_group.to_s[0..5].center(6), migration.name]
|
70
84
|
end
|
71
85
|
end
|
72
86
|
end
|
@@ -77,8 +91,8 @@ module MigrationTools
|
|
77
91
|
def define_migrate_group
|
78
92
|
namespace :db do
|
79
93
|
namespace :migrate do
|
80
|
-
desc
|
81
|
-
task :
|
94
|
+
desc "Runs pending migrations for a given group"
|
95
|
+
task group: :environment do
|
82
96
|
if group.empty?
|
83
97
|
notify "Please specify a migration group"
|
84
98
|
elsif pending_migrations.empty?
|
@@ -88,8 +102,14 @@ module MigrationTools
|
|
88
102
|
migrator(migration.version).run
|
89
103
|
end
|
90
104
|
|
91
|
-
|
92
|
-
|
105
|
+
schema_format = if ActiveRecord::VERSION::MAJOR >= 7
|
106
|
+
ActiveRecord.schema_format
|
107
|
+
else
|
108
|
+
ActiveRecord::Base.schema_format
|
109
|
+
end
|
110
|
+
|
111
|
+
Rake::Task["db:schema:dump"].invoke if schema_format == :ruby
|
112
|
+
Rake::Task["db:structure:dump"].invoke if schema_format == :sql
|
93
113
|
end
|
94
114
|
end
|
95
115
|
end
|
@@ -99,10 +119,10 @@ module MigrationTools
|
|
99
119
|
def define_convenience_tasks
|
100
120
|
namespace :db do
|
101
121
|
namespace :migrate do
|
102
|
-
[
|
122
|
+
[:list, :group].each do |ns|
|
103
123
|
namespace ns do
|
104
124
|
MigrationTools::MIGRATION_GROUPS.each do |migration_group|
|
105
|
-
desc "#{ns == :list ?
|
125
|
+
desc "#{(ns == :list) ? "Lists" : "Executes"} the migrations for group #{migration_group}"
|
106
126
|
task migration_group => :environment do
|
107
127
|
self.group = migration_group.to_s
|
108
128
|
Rake::Task["db:migrate:#{ns}"].invoke
|
@@ -133,7 +153,7 @@ module MigrationTools
|
|
133
153
|
if group.empty?
|
134
154
|
puts string
|
135
155
|
else
|
136
|
-
puts string
|
156
|
+
puts "#{string} for group \"#{group}\""
|
137
157
|
end
|
138
158
|
end
|
139
159
|
end
|
data/lib/migration_tools.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "benchmark"
|
2
|
+
require "active_record"
|
3
|
+
require "active_record/migration"
|
4
|
+
require "active_support/core_ext/object/blank"
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
6
|
+
require "migration_tools/migration_extension"
|
7
|
+
require "migration_tools/tasks"
|
8
8
|
|
9
9
|
module MigrationTools
|
10
10
|
def self.forced?
|
@@ -15,5 +15,5 @@ module MigrationTools
|
|
15
15
|
@forced = true
|
16
16
|
end
|
17
17
|
|
18
|
-
MIGRATION_GROUPS = [
|
18
|
+
MIGRATION_GROUPS = ["before", "during", "after", "change"]
|
19
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: migration_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Morten Primdahl
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,20 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '7.1'
|
19
|
+
version: 6.0.0
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '7.1'
|
26
|
+
version: 6.0.0
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: rake
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,6 +108,20 @@ dependencies:
|
|
114
108
|
- - ">="
|
115
109
|
- !ruby/object:Gem::Version
|
116
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: standard
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
117
125
|
description: Rake tasks for Rails that add groups to migrations
|
118
126
|
email: morten@zendesk.com
|
119
127
|
executables: []
|
@@ -127,7 +135,7 @@ homepage: https://github.com/zendesk/migration_tools
|
|
127
135
|
licenses:
|
128
136
|
- Apache-2.0
|
129
137
|
metadata: {}
|
130
|
-
post_install_message:
|
138
|
+
post_install_message:
|
131
139
|
rdoc_options: []
|
132
140
|
require_paths:
|
133
141
|
- lib
|
@@ -135,15 +143,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
143
|
requirements:
|
136
144
|
- - ">="
|
137
145
|
- !ruby/object:Gem::Version
|
138
|
-
version: 2.
|
146
|
+
version: 2.7.0
|
139
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
148
|
requirements:
|
141
149
|
- - ">="
|
142
150
|
- !ruby/object:Gem::Version
|
143
151
|
version: '0'
|
144
152
|
requirements: []
|
145
|
-
rubygems_version: 3.
|
146
|
-
signing_key:
|
153
|
+
rubygems_version: 3.5.11
|
154
|
+
signing_key:
|
147
155
|
specification_version: 4
|
148
156
|
summary: Encourage migrations that do not require downtime
|
149
157
|
test_files: []
|