tasks-migration 0.0.1
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 +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/README.md +79 -0
- data/lib/capistrano3/tasks/tasks_migration.rake +14 -0
- data/lib/capistrano3/tasks-migration.rb +1 -0
- data/lib/generators/tasks_migration/install_generator.rb +38 -0
- data/lib/generators/tasks_migration/task_generator.rb +14 -0
- data/lib/generators/tasks_migration/templates/migration.rb +7 -0
- data/lib/generators/tasks_migration/templates/task.rb +5 -0
- data/lib/generators/tasks_migration/templates/tasks_migration.yml +3 -0
- data/lib/models/tasks_migration_schema.rb +3 -0
- data/lib/tasks-migration.rb +1 -0
- data/lib/tasks_migration/migrate.rb +25 -0
- data/lib/tasks_migration/tasks/tasks_migration.rake +8 -0
- data/lib/tasks_migration/tasks_migration.rb +3 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3819807335af95ccb427e285be7b1a1de33de62121de2e02dc84ef91b2beb7bd
|
4
|
+
data.tar.gz: b4fddc32fbbbed607aac80e1cde9f1b055fad5ac29585341e174797391647594
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26cc0a5b760811dc70cfbfd7399d8b2839188a52576de844da203194fe7a265f0e791c0898384f5e5fd4c018c201dc41647d9c34893822b2b14f5590265f1e98
|
7
|
+
data.tar.gz: f5f04b6dcac6ad14fecf802ea16368d3fda732abe502fca9bfb8123b8413ec4e8e3eaa781d686301a4ed0dd093a07664e2909557509f8f085e3229d9373d1f15
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 NamNV609
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Tasks Migration
|
2
|
+
|
3
|
+
## Getting started
|
4
|
+
Tasks Migration works with Rails 4.1 onwards. Add the following line to your Gemfile
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
gem "tasks-migration"
|
8
|
+
```
|
9
|
+
|
10
|
+
Then run
|
11
|
+
|
12
|
+
```
|
13
|
+
bundle install
|
14
|
+
```
|
15
|
+
|
16
|
+
Next, you need to run the generator:
|
17
|
+
|
18
|
+
```
|
19
|
+
rails generate tasks_migration:install
|
20
|
+
```
|
21
|
+
|
22
|
+
This command will create 2 files:
|
23
|
+
|
24
|
+
* `db/migrate/<timestamp>_create_tasks_migration_schema.rb` (Create new table tasks_migration_schema in database)
|
25
|
+
* `config/tasks_migration.yml` (Define Tasks will be runs )
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
### Basic
|
30
|
+
|
31
|
+
Create a new task by command:
|
32
|
+
|
33
|
+
```
|
34
|
+
rails generate tasks_migration:task <TaskName>
|
35
|
+
```
|
36
|
+
|
37
|
+
Business Logic will be handled in method `self.excute` on file `app/migration_tasks/<task_name>.rb`. Example:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
# app/migration_tasks/hello_world_task.rb
|
41
|
+
class HelloWorldTask
|
42
|
+
def self.execute
|
43
|
+
puts "Hello world :D"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
And add this task into `config/tasks_migration.yml`. Example:
|
49
|
+
|
50
|
+
```yaml
|
51
|
+
# config/tasks_migration.yml
|
52
|
+
tasks:
|
53
|
+
- HelloWorldTask
|
54
|
+
```
|
55
|
+
|
56
|
+
The last, you run command:
|
57
|
+
|
58
|
+
```
|
59
|
+
bundle exec rake tasks_migration:migrate
|
60
|
+
```
|
61
|
+
|
62
|
+
### Capistrano
|
63
|
+
|
64
|
+
|
65
|
+
Using Tasks Migration with Capistrano (after deploying completed `deploy:finished`) we just need to add following line into `Capfile`:
|
66
|
+
|
67
|
+
```
|
68
|
+
require "capistrano3/tasks-migration"
|
69
|
+
```
|
70
|
+
|
71
|
+
Another way, you also can do it manually through `Capistrano Task`:
|
72
|
+
|
73
|
+
```
|
74
|
+
bundle exec cap <stage> tasks_migration:migrate
|
75
|
+
```
|
76
|
+
|
77
|
+
# Credits
|
78
|
+
|
79
|
+
Special thanks to [**ThanhTT**](https://github.com/thanhtt) for this file (**README.md**)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
namespace :tasks_migration do
|
2
|
+
desc "Migrate the tasks"
|
3
|
+
task :migrate do
|
4
|
+
on roles(:db) do
|
5
|
+
within release_path do
|
6
|
+
with rails_env: fetch(:rails_env) do
|
7
|
+
execute :rake, "tasks_migration:migrate"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
after "deploy:finished", "tasks_migration:migrate"
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path "../tasks/tasks_migration.rake", __FILE__
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
require "rails/generators/migration"
|
3
|
+
|
4
|
+
module TasksMigration
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < ::Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
|
9
|
+
source_root File.expand_path("../templates", __FILE__)
|
10
|
+
|
11
|
+
desc "Add setting files and create tasks folder"
|
12
|
+
def copy_config
|
13
|
+
copy_file "tasks_migration.yml", "config/tasks_migration.yml"
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Add migration for Tasks Migration"
|
17
|
+
def copy_migrations
|
18
|
+
migration_path = File.join "db", "migrate"
|
19
|
+
migration_template "migration.rb", "#{migration_path}/create_tasks_migration_schema.rb",
|
20
|
+
migration_version: migration_version
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.next_migration_number path
|
24
|
+
next_migration_number = current_migration_number(path) + 1
|
25
|
+
|
26
|
+
ActiveRecord::Migration.next_migration_number next_migration_number
|
27
|
+
end
|
28
|
+
|
29
|
+
def rails5_and_up?
|
30
|
+
Rails::VERSION::MAJOR >= 5
|
31
|
+
end
|
32
|
+
|
33
|
+
def migration_version
|
34
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" if rails5_and_up?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module TasksMigration
|
4
|
+
module Generators
|
5
|
+
class TaskGenerator < ::Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
desc "Add new migration task"
|
9
|
+
def add_task
|
10
|
+
template "task.rb", "app/migration_tasks/#{name.underscore}_task.rb", name: name
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "tasks_migration/tasks_migration"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "active_record"
|
2
|
+
require "models/tasks_migration_schema"
|
3
|
+
|
4
|
+
module TasksMigration
|
5
|
+
module Migrate
|
6
|
+
class << self
|
7
|
+
def start
|
8
|
+
all_tasks = get_all_tasks
|
9
|
+
executed_tasks = TasksMigrationSchema.pluck :version
|
10
|
+
|
11
|
+
(all_tasks - executed_tasks).each do |task|
|
12
|
+
puts "Running task #{task}..."
|
13
|
+
task.constantize.execute
|
14
|
+
TasksMigrationSchema.create version: task
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def get_all_tasks
|
20
|
+
tasks_file_path = ::Rails.root.join "config", "tasks_migration.yml"
|
21
|
+
YAML.load_file(tasks_file_path)["tasks"] || []
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tasks-migration
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- NamNV609
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Running tasks for Rails as migration
|
14
|
+
email: namnv609@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- CHANGELOG.md
|
20
|
+
- LICENSE
|
21
|
+
- README.md
|
22
|
+
- lib/capistrano3/tasks-migration.rb
|
23
|
+
- lib/capistrano3/tasks/tasks_migration.rake
|
24
|
+
- lib/generators/tasks_migration/install_generator.rb
|
25
|
+
- lib/generators/tasks_migration/task_generator.rb
|
26
|
+
- lib/generators/tasks_migration/templates/migration.rb
|
27
|
+
- lib/generators/tasks_migration/templates/task.rb
|
28
|
+
- lib/generators/tasks_migration/templates/tasks_migration.yml
|
29
|
+
- lib/models/tasks_migration_schema.rb
|
30
|
+
- lib/tasks-migration.rb
|
31
|
+
- lib/tasks_migration/migrate.rb
|
32
|
+
- lib/tasks_migration/tasks/tasks_migration.rake
|
33
|
+
- lib/tasks_migration/tasks_migration.rb
|
34
|
+
homepage: https://github.com/namnv609/tasks-migration
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.7.6
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Allow run tasks as like as migration
|
58
|
+
test_files: []
|