migration_tools 1.9.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 +31 -28
- data/lib/migration_tools.rb +7 -7
- metadata +20 -12
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,34 +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
34
|
ActiveRecord::Base.connection.schema_migration
|
35
35
|
).migrations, target_version)
|
36
|
-
elsif ActiveRecord
|
36
|
+
elsif ActiveRecord.gem_version >= Gem::Version.new("7.2")
|
37
37
|
migrate_up(ActiveRecord::MigrationContext.new(
|
38
38
|
migrations_paths,
|
39
|
-
ActiveRecord::
|
39
|
+
ActiveRecord::Base.connection_pool.schema_migration
|
40
40
|
).migrations, target_version)
|
41
|
-
elsif ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR == 2
|
42
|
-
migrate_up(ActiveRecord::MigrationContext.new(migrations_paths).migrations, target_version)
|
43
41
|
else
|
44
|
-
migrate_up(ActiveRecord::
|
42
|
+
migrate_up(ActiveRecord::MigrationContext.new(
|
43
|
+
migrations_paths,
|
44
|
+
ActiveRecord::SchemaMigration
|
45
|
+
).migrations, target_version)
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
49
|
def migrate_up(migrations, target_version)
|
49
|
-
if ActiveRecord::VERSION::MAJOR
|
50
|
+
if ActiveRecord::VERSION::MAJOR == 7 && ActiveRecord::VERSION::MINOR == 1
|
50
51
|
ActiveRecord::Migrator.new(:up, migrations,
|
51
52
|
ActiveRecord::Base.connection.schema_migration,
|
52
53
|
ActiveRecord::Base.connection.internal_metadata,
|
53
|
-
target_version
|
54
|
-
|
55
|
-
|
56
|
-
|
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)
|
57
60
|
else
|
58
|
-
ActiveRecord::Migrator.new(:up, migrations, target_version)
|
61
|
+
ActiveRecord::Migrator.new(:up, migrations, ActiveRecord::SchemaMigration, target_version)
|
59
62
|
end
|
60
63
|
end
|
61
64
|
|
@@ -70,14 +73,14 @@ module MigrationTools
|
|
70
73
|
def define_migrate_list
|
71
74
|
namespace :db do
|
72
75
|
namespace :migrate do
|
73
|
-
desc
|
74
|
-
task :
|
76
|
+
desc "Lists pending migrations"
|
77
|
+
task list: :environment do
|
75
78
|
if pending_migrations.empty?
|
76
79
|
notify "Your database schema is up to date", group
|
77
80
|
else
|
78
81
|
notify "You have #{pending_migrations.size} pending migrations", group
|
79
82
|
pending_migrations.each do |migration|
|
80
|
-
notify
|
83
|
+
notify " %4d %s %s" % [migration.version, migration.migration_group.to_s[0..5].center(6), migration.name]
|
81
84
|
end
|
82
85
|
end
|
83
86
|
end
|
@@ -88,8 +91,8 @@ module MigrationTools
|
|
88
91
|
def define_migrate_group
|
89
92
|
namespace :db do
|
90
93
|
namespace :migrate do
|
91
|
-
desc
|
92
|
-
task :
|
94
|
+
desc "Runs pending migrations for a given group"
|
95
|
+
task group: :environment do
|
93
96
|
if group.empty?
|
94
97
|
notify "Please specify a migration group"
|
95
98
|
elsif pending_migrations.empty?
|
@@ -100,10 +103,10 @@ module MigrationTools
|
|
100
103
|
end
|
101
104
|
|
102
105
|
schema_format = if ActiveRecord::VERSION::MAJOR >= 7
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
106
|
+
ActiveRecord.schema_format
|
107
|
+
else
|
108
|
+
ActiveRecord::Base.schema_format
|
109
|
+
end
|
107
110
|
|
108
111
|
Rake::Task["db:schema:dump"].invoke if schema_format == :ruby
|
109
112
|
Rake::Task["db:structure:dump"].invoke if schema_format == :sql
|
@@ -116,10 +119,10 @@ module MigrationTools
|
|
116
119
|
def define_convenience_tasks
|
117
120
|
namespace :db do
|
118
121
|
namespace :migrate do
|
119
|
-
[
|
122
|
+
[:list, :group].each do |ns|
|
120
123
|
namespace ns do
|
121
124
|
MigrationTools::MIGRATION_GROUPS.each do |migration_group|
|
122
|
-
desc "#{ns == :list ?
|
125
|
+
desc "#{(ns == :list) ? "Lists" : "Executes"} the migrations for group #{migration_group}"
|
123
126
|
task migration_group => :environment do
|
124
127
|
self.group = migration_group.to_s
|
125
128
|
Rake::Task["db:migrate:#{ns}"].invoke
|
@@ -150,7 +153,7 @@ module MigrationTools
|
|
150
153
|
if group.empty?
|
151
154
|
puts string
|
152
155
|
else
|
153
|
-
puts string
|
156
|
+
puts "#{string} for group \"#{group}\""
|
154
157
|
end
|
155
158
|
end
|
156
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
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.2'
|
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.2'
|
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: []
|
@@ -135,14 +143,14 @@ 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.
|
153
|
+
rubygems_version: 3.5.11
|
146
154
|
signing_key:
|
147
155
|
specification_version: 4
|
148
156
|
summary: Encourage migrations that do not require downtime
|