rake_migrations 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b96467d0ed517f140a47e2d1c054ce721d3b7681
4
+ data.tar.gz: feb3922147c3656d8cb035dbb26dd6e5df9563fb
5
+ SHA512:
6
+ metadata.gz: ee2ee75676afbbe6d790bee69b728f281fd76011035611ff2351aeef245f8f339dc4dbc26ed53b28e21b58adfebd466c94c0382742689afc39ff2753be44d3c6
7
+ data.tar.gz: 6a973b74670610498e87a95bcfce942571b04c4db49da31a940626b0eebaf26912cd771936d2f078b0f7be1034b060dd142447d25fe25c87a65c4630bc1692c5
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ Rake Migrations
2
+ ===============
3
+ [![Build Status](https://travis-ci.org/eyaleizenberg/rake-migrations.svg?branch=master)](https://travis-ci.org/eyaleizenberg/rake-migrations)
4
+
5
+ This gem helps you and your team members keep track of 'run once' rake tasks.
6
+
7
+ ## Requirements
8
+ At the moment I have only tested this on Rails 3.2.X running mysql2 on Mac OS X.
9
+ If you can help by testing this on different versions, databases and platforms, let me know.
10
+
11
+ ## Installation
12
+ First, add this this to your gemfile:
13
+ ```ruby
14
+ gem 'rake_migrations'
15
+ ```
16
+
17
+ Then, run:
18
+ ```ruby
19
+ bundle install
20
+ rails g rake_migrations:install
21
+ rake db:migrate
22
+ ```
23
+
24
+ ## Use
25
+ Whenever somebody from your team wants to create a new run once task, simply generate it by running:
26
+
27
+ ```ruby
28
+ rails g task <namespace> <task>
29
+ ```
30
+
31
+ For example:
32
+
33
+ ```ruby
34
+ rails g task users:update_some_field
35
+ ```
36
+
37
+ This will generate a file under 'lib/tasks/rake_migrations' with a timestamp and the following content:
38
+
39
+ ```ruby
40
+ # Checklist:
41
+ # 1. Re-runnable on production?
42
+ # 2. Is there a chance emails will be sent?
43
+ # 3. puts ids & logs (progress log)
44
+ # 4. Can you update the records with an update all instead of instantizing?
45
+ # 5. Are there any callbacks?
46
+ # 6. Performance issues?
47
+ # 7. Scoping to account
48
+
49
+ namespace :users do
50
+ desc "update run_at field to get value as in start_time"
51
+ task update_some_field: [:environment] do
52
+
53
+ # DO NOT REMOVE THIS PART
54
+ RakeMigration.find_or_create_by_version(__FILE__[/\d+/])
55
+ end
56
+ end
57
+ ```
58
+
59
+ 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:
60
+
61
+ ```ruby
62
+ rake users:update_some_field
63
+ ```
64
+
65
+ Commit your new file into your repository.
66
+
67
+ Afterwards, through the magic of git-hooks, whenever someone pulls this branch (or a branch that has this file in it), he will see a message in the terminal telling him which rakes need to be run:
68
+
69
+ ```ruby
70
+ You need to run the following rakes:
71
+ ------------------------------------
72
+ rake users:update_some_field
73
+ ```
74
+
75
+ ## Issues, suggestions and forks.
76
+ Feel free to open issues, send suggestions and fork this repository.
77
+
78
+ Thanks and Enjoy! :)
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'RakeMigrations'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,30 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+ require 'rails/generators/active_record'
4
+
5
+ module RakeMigrations
6
+ class InstallGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+ extend ActiveRecord::Generators::Migration
9
+ source_root File.expand_path('../templates', __FILE__)
10
+
11
+ def create_migration_file
12
+ migration_template "migration.rb", "db/migrate/create_rake_migrations_table.rb"
13
+ template("rake_migrations_check.rb", "config/rake_migrations_check.rb")
14
+ write_to_post_merge_hook
15
+ end
16
+
17
+ def write_to_post_merge_hook
18
+ post_merge_file = ".git/hooks/post-merge"
19
+ what_to_write = <<-TEXT
20
+ #{!File.exists?(post_merge_file) ? '#!/bin/sh' : ''}
21
+ ruby ./config/rake_migrations_check.rb
22
+ TEXT
23
+
24
+ File.open(post_merge_file, 'a+') do |file|
25
+ file.write(what_to_write) unless file.read.match(/rake_migrations_check/)
26
+ end
27
+ `chmod 777 #{post_merge_file}`
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ class CreateRakeMigrationsTable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :rake_migrations do |t|
4
+ t.string :version
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table :rake_migrations
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ require 'mysql2'
2
+
3
+ module RakeMigrationsCheck
4
+ def self.check
5
+ client = Mysql2::Client.new(host: "localhost", username: "root", database: "samanage_development")
6
+ results = client.query("select * from rake_migrations").map {|res| res["version"] }
7
+ rake_migrations_lib = "#{`pwd`.strip}/lib/tasks/rake_migrations/*"
8
+
9
+ rake_files = Dir[rake_migrations_lib].map do |file|
10
+ if !results.include?(file[/\d+/])
11
+ file = File.read(file)
12
+ namespace = file[/namespace :(.*?)do/m, 1].strip
13
+ task = file[/task (.*?):/m, 1]
14
+ "rake #{namespace}:#{task}"
15
+ end
16
+ end.compact
17
+
18
+ if !rake_files.empty?
19
+ puts "\n"
20
+ puts "You need to run the following rakes:"
21
+ puts "------------------------------------"
22
+ rake_files.each { |file| puts "\e[31m#{file}\e[0m" }
23
+ puts "\n"
24
+ end
25
+ end
26
+ end
27
+
28
+ RakeMigrationsCheck.check
@@ -0,0 +1,8 @@
1
+ Description:
2
+ This generator will create rake tasks with a time stamp and default messages.
3
+
4
+ Example:
5
+ rails generate task incidents convert_x_to_y
6
+
7
+ This will create:
8
+ lib/tasks/rake_migrations/[time_stamp]incidents.rake
@@ -0,0 +1,9 @@
1
+ class TaskGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ argument :actions, type: :array, default: [], banner: "action action"
4
+
5
+ def create_task_files
6
+ time_stamp = Time.now.strftime("%Y%m%d%H%M")
7
+ template 'task.rb', File.join('lib/tasks/rake_migrations', "#{time_stamp}_#{file_name}.rake")
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ # Checklist:
2
+ # 1. Re-runnable on production?
3
+ # 2. Is there a chance emails will be sent?
4
+ # 3. puts ids & logs (progress log)
5
+ # 4. Can you update the records with an update all instead of instantizing?
6
+ # 5. Are there any callbacks?
7
+ # 6. Performance issues?
8
+ # 7. Scoping to account
9
+
10
+ namespace :<%= file_name %> do
11
+ <% actions.each do |action| -%>
12
+ desc "TODO"
13
+ task <%= action %>: [:environment] do
14
+
15
+
16
+ # DO NOT REMOVE THIS PART
17
+ RakeMigration.find_or_create_by_version(__FILE__[/\d+/])
18
+ end
19
+
20
+ <% end -%>
21
+ end
@@ -0,0 +1,2 @@
1
+ module RakeMigrations
2
+ end
@@ -0,0 +1,3 @@
1
+ module RakeMigrations
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake_migrations
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eyal Eizenberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mysql2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: This gem creates a rake_migrations table and keeps track of rake tasks
42
+ similar to migrations.
43
+ email:
44
+ - iz.eyal@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - MIT-LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - lib/rails/generators/rake_migrations/install_generator.rb
53
+ - lib/rails/generators/rake_migrations/templates/migration.rb
54
+ - lib/rails/generators/rake_migrations/templates/rake_migrations_check.rb
55
+ - lib/rails/generators/task/USAGE
56
+ - lib/rails/generators/task/task_generator.rb
57
+ - lib/rails/generators/task/templates/task.rb
58
+ - lib/rake_migrations.rb
59
+ - lib/rake_migrations/version.rb
60
+ homepage: http://eyaleizenberg.blogspot.com/
61
+ licenses: []
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: A gem to easily keep track of rake tasks
83
+ test_files: []