rake_migrations 1.0.8 → 1.0.9
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/README.md +1 -3
- data/lib/rails/generators/rake_migrations/templates/rake_migrations_check.rb +7 -6
- data/lib/rails/generators/rake_migrations/templates/rake_migrations_check_pg.rb +7 -7
- data/lib/rails/generators/task/templates/task.rb +1 -5
- data/lib/rake_migration.rb +17 -1
- data/lib/rake_migrations/version.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68011dc09f0dfa5ff07666c91b53984cd8d93a40
|
4
|
+
data.tar.gz: be401fe1911da6d7f15575000e3c071df66a191c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 001216c2a2fa11b0fdc954fb5203de242d64f3300b657883c6cba643e0ecfbc0022906280b2279e9da4d8ce0447f3e918356709e6ec21f47cf89ad7e38e6fabe
|
7
|
+
data.tar.gz: 4d736d12e2811bad71b00c79c23b7f7dcd23b653e7ce11e1e49560bfc535e6f29df629de7a0be6081b533ae6786a773db6f31c563b33f5cfbd76156c061fb11b
|
data/README.md
CHANGED
@@ -72,13 +72,11 @@ namespace :users do
|
|
72
72
|
User.update_all({role_id: 1}, {role_id: 2})
|
73
73
|
|
74
74
|
# DO NOT REMOVE THIS PART
|
75
|
-
RakeMigration.
|
75
|
+
RakeMigration.mark_complete(__FILE__)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
```
|
79
79
|
|
80
|
-
Update: If you are using Rails 4 or greater, the find_or_create_by_version has been changed to find_or_create_by(version: __FILE__[/\d+/]).
|
81
|
-
|
82
80
|
Simply insert your code above the "DO NOT REMOVE THIS PART" line. The checklist is there to help you and the person who is code-reviewing your code to think of problems that might occur from your rake task. Afterwards you can run the rake task normally:
|
83
81
|
|
84
82
|
```ruby
|
@@ -6,12 +6,13 @@ module RakeMigrationsCheck
|
|
6
6
|
results = client.query("select * from rake_migrations").map {|res| res["version"] }
|
7
7
|
rake_migrations_lib = "#{`pwd`.strip}/lib/tasks/rake_migrations/*"
|
8
8
|
|
9
|
-
rake_files = Dir[rake_migrations_lib].map do |file|
|
10
|
-
|
9
|
+
rake_files = Dir[rake_migrations_lib].sort.map do |file|
|
10
|
+
rake_id = RakeMigration.version_from_path(file)
|
11
|
+
if !results.include?(rake_id)
|
11
12
|
file = File.read(file)
|
12
|
-
namespace = file[/namespace
|
13
|
-
task = file[/task (
|
14
|
-
"rake #{namespace}:#{task}"
|
13
|
+
namespace = file[/namespace :?([^: ,]*)/m, 1].strip
|
14
|
+
task = file[/task :?([^ :,]*)/m, 1]
|
15
|
+
"rake #{namespace}:#{task} # #{rake_id}"
|
15
16
|
end
|
16
17
|
end.compact
|
17
18
|
|
@@ -25,4 +26,4 @@ module RakeMigrationsCheck
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
RakeMigrationsCheck.check
|
29
|
+
RakeMigrationsCheck.check
|
@@ -4,15 +4,15 @@ module RakeMigrationsCheck
|
|
4
4
|
def self.check
|
5
5
|
client = PG.connect(host: "localhost", user: "<username>", dbname: "<database name>")
|
6
6
|
results = client.exec("select * from rake_migrations").map {|res| res["version"] }
|
7
|
-
|
8
7
|
rake_migrations_lib = "#{`pwd`.strip}/lib/tasks/rake_migrations/*"
|
9
8
|
|
10
|
-
rake_files = Dir[rake_migrations_lib].map do |file|
|
11
|
-
|
9
|
+
rake_files = Dir[rake_migrations_lib].sort.map do |file|
|
10
|
+
rake_id = RakeMigration.version_from_path(file)
|
11
|
+
if !results.include?(rake_id)
|
12
12
|
file = File.read(file)
|
13
|
-
namespace = file[/namespace
|
14
|
-
task = file[/task (
|
15
|
-
"rake #{namespace}:#{task}"
|
13
|
+
namespace = file[/namespace :?([^: ,]*)/m, 1].strip
|
14
|
+
task = file[/task :?([^ :,]*)/m, 1]
|
15
|
+
"rake #{namespace}:#{task} # #{rake_id}"
|
16
16
|
end
|
17
17
|
end.compact
|
18
18
|
|
@@ -26,4 +26,4 @@ module RakeMigrationsCheck
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
RakeMigrationsCheck.check
|
29
|
+
RakeMigrationsCheck.check
|
@@ -14,11 +14,7 @@ namespace :<%= file_name %> do
|
|
14
14
|
|
15
15
|
|
16
16
|
# DO NOT REMOVE THIS PART
|
17
|
-
|
18
|
-
RakeMigration.find_or_create_by_version(__FILE__[/\d+/])
|
19
|
-
<% else -%>
|
20
|
-
RakeMigration.find_or_create_by(version: __FILE__[/\d+/])
|
21
|
-
<% end -%>
|
17
|
+
RakeMigration.mark_complete(__FILE__)
|
22
18
|
end
|
23
19
|
<% end -%>
|
24
20
|
end
|
data/lib/rake_migration.rb
CHANGED
@@ -1,2 +1,18 @@
|
|
1
1
|
class RakeMigration < ::ActiveRecord::Base
|
2
|
-
|
2
|
+
def self.version_from_path(path)
|
3
|
+
path.split('/').last[/\d+/]
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.findcreate_by_version(rake_id)
|
7
|
+
find_or_create_by_version(rake_id)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.mark_complete(file)
|
11
|
+
rake_id = version_from_path(file)
|
12
|
+
if methods.include?(:find_or_create_by)
|
13
|
+
find_or_create_by(version: rake_id)
|
14
|
+
else
|
15
|
+
findcreate_by_version(rake_id)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module RakeMigrations
|
2
|
-
VERSION = "1.0.
|
3
|
-
end
|
2
|
+
VERSION = "1.0.9"
|
3
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rake_migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eyal Eizenberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
80
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.
|
81
|
+
rubygems_version: 2.6.14
|
82
82
|
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: A gem to easily keep track of rake tasks
|