active_record_tasks 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +74 -0
- data/Rakefile +11 -0
- data/active_record_tasks.gemspec +25 -0
- data/fixtures/db1/config.yml +3 -0
- data/fixtures/db1/migrate/.gitkeep +0 -0
- data/lib/active_record_tasks/tasks.rb +66 -0
- data/lib/active_record_tasks/templates/migrate.erb +5 -0
- data/lib/active_record_tasks/version.rb +3 -0
- data/lib/active_record_tasks.rb +21 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4656e942f85998ecbf622c34e6f11557cdb913c7
|
4
|
+
data.tar.gz: 33cdecb280595f4a3d3c6cf06c6feb37610fd582
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d006421419ee9285dfe484b69b64ce8cad2d071ae159178c1b6a807f2f880952135b9d4418b5680a7a53f0541b915c3547a05de42d1fca8eade60a2e880a547
|
7
|
+
data.tar.gz: 6e49550a193d8844b9d26a934d288ee1d65a30f9764bcc0d61b8d341d175fac5100681c92d11e928efa345b5b033dda18c47a51b74b1a5ea0e0a1a749cb08645
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Gilbert
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# ActiveRecordTasks
|
2
|
+
|
3
|
+
The easiest way to get started with ActiveRecord 4 in a non-rails project.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'active_record_tasks', '~> 1.0.0'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install active_record_tasks
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Include the following in your `Rakefile`:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'active_record_tasks'
|
25
|
+
|
26
|
+
ActiveRecordTasks.configure do |config|
|
27
|
+
# These are all the default values
|
28
|
+
config.db_dir = 'db'
|
29
|
+
config.db_config_path = 'db/config.yml'
|
30
|
+
config.env = 'test'
|
31
|
+
end
|
32
|
+
|
33
|
+
# Run this AFTER you've configured
|
34
|
+
ActiveRecordTasks.load_tasks
|
35
|
+
```
|
36
|
+
|
37
|
+
Now you have access to all the ActiveRecord db tasks!
|
38
|
+
|
39
|
+
```
|
40
|
+
$ rake -T
|
41
|
+
rake db:create # Creates the database from DATABASE_URL or config/database.yml for the ...
|
42
|
+
rake db:drop # Drops the database from DATABASE_URL or config/database.yml for the cu...
|
43
|
+
rake db:fixtures:load # Load fixtures into the current environment's database
|
44
|
+
rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
|
45
|
+
rake db:migrate:status # Display status of migrations
|
46
|
+
rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n)
|
47
|
+
rake db:schema:cache:clear # Clear a db/schema_cache.dump file
|
48
|
+
rake db:schema:cache:dump # Create a db/schema_cache.dump file
|
49
|
+
rake db:schema:dump # Create a db/schema.rb file that is portable against any DB supported b...
|
50
|
+
rake db:schema:load # Load a schema.rb file into the database
|
51
|
+
rake db:seed # Load the seed data from db/seeds.rb
|
52
|
+
rake db:setup # Create the database, load the schema, and initialize with the seed dat...
|
53
|
+
rake db:structure:dump # Dump the database structure to db/structure.sql
|
54
|
+
rake db:version # Retrieves the current schema version number
|
55
|
+
...
|
56
|
+
```
|
57
|
+
|
58
|
+
## Basic Generate Migration
|
59
|
+
|
60
|
+
This gem provides a bonus `generate:migration` task. It's very basic, but it works:
|
61
|
+
|
62
|
+
```
|
63
|
+
rake generate:migration name=CreateUsers
|
64
|
+
```
|
65
|
+
|
66
|
+
This will create a timestamped file in your configured db directory (`db/migrate/` by default).
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
1. Fork it
|
71
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
72
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
73
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
74
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# # # # # # # # # # # # # # # # #
|
2
|
+
# This file is used for testing #
|
3
|
+
# # # # # # # # # # # # # # # # #
|
4
|
+
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
require 'active_record_tasks'
|
7
|
+
|
8
|
+
ActiveRecordTasks.configure do |config|
|
9
|
+
config.db_dir = './fixtures/db1'
|
10
|
+
end
|
11
|
+
ActiveRecordTasks.load_tasks
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'active_record_tasks/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "active_record_tasks"
|
8
|
+
spec.version = ActiveRecordTasks::VERSION
|
9
|
+
spec.authors = ["Gilbert"]
|
10
|
+
spec.email = ["gilbertbgarza@gmail.com"]
|
11
|
+
spec.description = %q{Use ActiveRecord 4 in non-rails projects.}
|
12
|
+
spec.summary = %q{The easiest way to get started with ActiveRecord 4 in a non-rails project.}
|
13
|
+
spec.homepage = "https://github.com/makersquare/active_record_tasks"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activerecord", "~> 4.1"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
File without changes
|
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
config = ActiveRecordTasks.config
|
3
|
+
config.db_dir ||= 'db'
|
4
|
+
config.db_config_path ||= File.join(config.db_dir, 'config.yml')
|
5
|
+
config.env ||= 'test'
|
6
|
+
|
7
|
+
# This is needed to overwrite the already-existing Rake task "load_config"
|
8
|
+
class Rake::Task
|
9
|
+
def overwrite(&block)
|
10
|
+
@actions.clear
|
11
|
+
enhance(&block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Load the ActiveRecord tasks
|
16
|
+
spec = Gem::Specification.find_by_name("activerecord")
|
17
|
+
load File.join(spec.gem_dir, "lib/active_record/railties/databases.rake")
|
18
|
+
|
19
|
+
# Overwrite the load config to your needs
|
20
|
+
Rake::Task["db:load_config"].overwrite do
|
21
|
+
ActiveRecord::Base.configurations = ActiveRecord::Tasks::DatabaseTasks.database_configuration = YAML.load File.read(config.db_config_path)
|
22
|
+
ActiveRecord::Tasks::DatabaseTasks.db_dir = config.db_dir
|
23
|
+
ActiveRecord::Tasks::DatabaseTasks.env = config.env
|
24
|
+
end
|
25
|
+
|
26
|
+
# Migrations need an environment with an already established database connection
|
27
|
+
task :environment => ["db:load_config"] do
|
28
|
+
ActiveRecord::Base.establish_connection ActiveRecord::Tasks::DatabaseTasks.database_configuration[ActiveRecord::Tasks::DatabaseTasks.env]
|
29
|
+
end
|
30
|
+
|
31
|
+
# Simple migration generator
|
32
|
+
namespace :generate do
|
33
|
+
desc "Creates a new migration file with the specified name"
|
34
|
+
task :migration => :environment do |t, args|
|
35
|
+
name = args[:name] || ENV['name']
|
36
|
+
|
37
|
+
unless name
|
38
|
+
puts "Error: must provide name of migration to generate."
|
39
|
+
puts "For example: rake #{t.name} name=add_field_to_form"
|
40
|
+
abort
|
41
|
+
end
|
42
|
+
|
43
|
+
# Require helper for `camelize` and `underscore`
|
44
|
+
require 'active_support/core_ext/string/inflections.rb'
|
45
|
+
|
46
|
+
# Generate file name based on time
|
47
|
+
# Anything more complicated that this would warrant its own file
|
48
|
+
template = File.read File.join(File.dirname(__FILE__), 'templates/migrate.erb')
|
49
|
+
result = ERB.new(template).result(binding)
|
50
|
+
|
51
|
+
timestamp = Time.now.strftime("%Y%m%d%H%M%S")
|
52
|
+
migration_path = File.join("#{config.db_dir}/migrate/#{timestamp}_#{name.underscore}.rb")
|
53
|
+
File.write(migration_path, result)
|
54
|
+
puts " create #{migration_path}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Alias `generate` namespace with `g`
|
59
|
+
rule "" do |tsk|
|
60
|
+
aliastask = tsk.name.sub(/g:/, 'generate:')
|
61
|
+
if Rake.application.tasks.map{|tsk| tsk.name }.include?( aliastask )
|
62
|
+
Rake.application[aliastask].invoke
|
63
|
+
else
|
64
|
+
raise RuntimeError, "Don't know how to build task '#{tsk.name}'"
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module ActiveRecordTasks
|
5
|
+
DatabaseConfig = Struct.new(:db_dir, :db_config_path, :env)
|
6
|
+
@config = DatabaseConfig.new
|
7
|
+
|
8
|
+
def self.configure
|
9
|
+
yield @config
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.config
|
13
|
+
@config
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.load_tasks
|
17
|
+
require 'active_record_tasks/tasks'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'active_record_tasks/version'
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_record_tasks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gilbert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Use ActiveRecord 4 in non-rails projects.
|
56
|
+
email:
|
57
|
+
- gilbertbgarza@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- active_record_tasks.gemspec
|
68
|
+
- fixtures/db1/config.yml
|
69
|
+
- fixtures/db1/migrate/.gitkeep
|
70
|
+
- lib/active_record_tasks.rb
|
71
|
+
- lib/active_record_tasks/tasks.rb
|
72
|
+
- lib/active_record_tasks/templates/migrate.erb
|
73
|
+
- lib/active_record_tasks/version.rb
|
74
|
+
homepage: https://github.com/makersquare/active_record_tasks
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.2.2
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: The easiest way to get started with ActiveRecord 4 in a non-rails project.
|
98
|
+
test_files: []
|