active_record_tasks 1.0.2 → 1.0.3
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 +14 -4
- data/Rakefile +1 -1
- data/active_record_tasks.gemspec +1 -0
- data/fixtures/db2/config.yml +3 -0
- data/lib/active_record_tasks/tasks.rb +52 -2
- data/lib/active_record_tasks/templates/config.erb +11 -0
- data/lib/active_record_tasks/version.rb +1 -1
- metadata +17 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ac78a2d5bb04d804ca7c9bfaf8b151ccbbe45f2
|
4
|
+
data.tar.gz: 4d1e78b507ca0451d47ba19c2a51095165114da0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4517445375502c934a17d3aeccbec8f873cbae89798e10c5515047f617e1c1e24b6a902e259ee3bc8e54158fedcb5694e938efae9c16d0854135017130e8aa58
|
7
|
+
data.tar.gz: a2fc3b58b0e8e578afb79c0c46264423175351b8785edf96c3f16c64068af4d7f3ea4c8721fa21491d9db20b695323c992804760d8717dea68f8a6fcf54bd39d
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ The easiest way to get started with ActiveRecord 4 in a non-rails project.
|
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem 'active_record_tasks', '~> 1.0.
|
9
|
+
gem 'active_record_tasks', '~> 1.0.3'
|
10
10
|
|
11
11
|
And then execute:
|
12
12
|
|
@@ -16,7 +16,7 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install active_record_tasks
|
18
18
|
|
19
|
-
##
|
19
|
+
## Getting Started
|
20
20
|
|
21
21
|
Include the following in your `Rakefile`:
|
22
22
|
|
@@ -34,7 +34,17 @@ end
|
|
34
34
|
ActiveRecordTasks.load_tasks
|
35
35
|
```
|
36
36
|
|
37
|
-
|
37
|
+
If this is a new project:
|
38
|
+
|
39
|
+
```
|
40
|
+
$ rake generate:init
|
41
|
+
```
|
42
|
+
|
43
|
+
will generate your configured db directory (if it doesn't exist).
|
44
|
+
|
45
|
+
## Usage
|
46
|
+
|
47
|
+
ActiveRecordTasks gives you access to all the ActiveRecord db tasks:
|
38
48
|
|
39
49
|
```
|
40
50
|
$ rake -T
|
@@ -55,7 +65,7 @@ rake db:version # Retrieves the current schema version number
|
|
55
65
|
...
|
56
66
|
```
|
57
67
|
|
58
|
-
|
68
|
+
### Generating Migrations
|
59
69
|
|
60
70
|
This gem provides a bonus `generate:migration` task. It's very basic, but it works:
|
61
71
|
|
data/Rakefile
CHANGED
data/active_record_tasks.gemspec
CHANGED
@@ -30,6 +30,50 @@ end
|
|
30
30
|
|
31
31
|
# Simple migration generator
|
32
32
|
namespace :generate do
|
33
|
+
require 'rainbow/ext/string'
|
34
|
+
def puts_exists(subject)
|
35
|
+
print "\texists\t".color(:cyan)
|
36
|
+
puts subject
|
37
|
+
end
|
38
|
+
def puts_create(subject)
|
39
|
+
print "\tcreate\t".color(:green)
|
40
|
+
puts subject
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "Generates a new db directory"
|
44
|
+
task :init do
|
45
|
+
# Create (configured) db and db/migrate directory
|
46
|
+
if File.directory?(config.db_dir)
|
47
|
+
puts_exists config.db_dir
|
48
|
+
else
|
49
|
+
puts_create config.db_dir
|
50
|
+
Dir.mkdir(config.db_dir)
|
51
|
+
end
|
52
|
+
|
53
|
+
migrate_dir = "#{config.db_dir}/migrate"
|
54
|
+
if File.directory?(migrate_dir)
|
55
|
+
puts_exists migrate_dir
|
56
|
+
else
|
57
|
+
puts_create migrate_dir
|
58
|
+
Dir.mkdir(migrate_dir)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Create basic config.yml file
|
62
|
+
db_config_path = config.db_config_path
|
63
|
+
if File.exist?(db_config_path)
|
64
|
+
puts_exists db_config_path
|
65
|
+
else
|
66
|
+
puts_create db_config_path
|
67
|
+
project_dir = File.basename(Dir.pwd)
|
68
|
+
template = File.read File.join(File.dirname(__FILE__), 'templates/config.erb')
|
69
|
+
result = ERB.new(template).result(binding)
|
70
|
+
|
71
|
+
File.write(db_config_path, result)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
|
33
77
|
desc "Creates a new migration file with the specified name"
|
34
78
|
task :migration => :environment do |t, args|
|
35
79
|
name = args[:name] || ENV['name']
|
@@ -48,10 +92,16 @@ namespace :generate do
|
|
48
92
|
template = File.read File.join(File.dirname(__FILE__), 'templates/migrate.erb')
|
49
93
|
result = ERB.new(template).result(binding)
|
50
94
|
|
95
|
+
# Ensure migrate directory exists
|
96
|
+
migrate_dir = "#{config.db_dir}/migrate"
|
97
|
+
unless File.directory?(migrate_dir)
|
98
|
+
Dir.mkdir(migrate_dir)
|
99
|
+
end
|
100
|
+
|
51
101
|
timestamp = Time.now.strftime("%Y%m%d%H%M%S")
|
52
|
-
migration_path = File.join("#{
|
102
|
+
migration_path = File.join(migrate_dir, "#{timestamp}_#{name.underscore}.rb")
|
53
103
|
File.write(migration_path, result)
|
54
|
-
|
104
|
+
puts_create migration_path
|
55
105
|
end
|
56
106
|
end
|
57
107
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilbert
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rainbow
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,8 +81,10 @@ files:
|
|
67
81
|
- active_record_tasks.gemspec
|
68
82
|
- fixtures/db1/config.yml
|
69
83
|
- fixtures/db1/migrate/.gitkeep
|
84
|
+
- fixtures/db2/config.yml
|
70
85
|
- lib/active_record_tasks.rb
|
71
86
|
- lib/active_record_tasks/tasks.rb
|
87
|
+
- lib/active_record_tasks/templates/config.erb
|
72
88
|
- lib/active_record_tasks/templates/migrate.erb
|
73
89
|
- lib/active_record_tasks/version.rb
|
74
90
|
homepage: https://github.com/makersquare/active_record_tasks
|