migratification 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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/History.txt +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +54 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/bin/migratify +124 -0
- data/lib/migratification.rb +3 -0
- data/migratification.gemspec +61 -0
- data/resources/rake/all/db.rake +113 -0
- data/resources/rake/optional/grails.rake +121 -0
- data/spec/migratification_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +80 -0
data/.document
ADDED
data/.gitignore
ADDED
data/History.txt
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jason Harrelson
|
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.rdoc
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
= migratification
|
2
|
+
|
3
|
+
http://github.com/midas/migratification
|
4
|
+
|
5
|
+
|
6
|
+
== DESCRIPTION
|
7
|
+
|
8
|
+
Generates a directory structure and assets to allow for using Active Record migrations within any project, Groovy, C\#, etc.
|
9
|
+
|
10
|
+
|
11
|
+
== FEATURES
|
12
|
+
|
13
|
+
* Creates a Rakefile
|
14
|
+
* Creates a rake directory to hold rake tasks
|
15
|
+
* Creates a db.rake file holding all of the database specific tasks
|
16
|
+
* Creates a grails.rake file holding all grails specific tasks (if specified with --grails option)
|
17
|
+
* Creates db/config and db/migrate directories to hold the migration specific scripts
|
18
|
+
|
19
|
+
|
20
|
+
== INSTALL
|
21
|
+
|
22
|
+
gem sources -a http://gemcutter.org
|
23
|
+
sudo gem install migratory
|
24
|
+
|
25
|
+
|
26
|
+
== USAGE
|
27
|
+
|
28
|
+
migratify ~/project
|
29
|
+
|
30
|
+
rake -T # to see all the tasks available
|
31
|
+
|
32
|
+
|
33
|
+
== Note on Patches/Pull Requests
|
34
|
+
|
35
|
+
* Fork the project.
|
36
|
+
* Make your feature addition or bug fix.
|
37
|
+
* Add tests for it. This is important so I don't break it in a
|
38
|
+
future version unintentionally.
|
39
|
+
* Commit, do not mess with rakefile, version, or history.
|
40
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
41
|
+
* Send me a pull request. Bonus points for topic branches.
|
42
|
+
|
43
|
+
|
44
|
+
== LICENSE
|
45
|
+
|
46
|
+
Copyright (c) 2009 C. Jason Harrelson (midas)
|
47
|
+
|
48
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
49
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
50
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
51
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
52
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
53
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
54
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "migratification"
|
8
|
+
gem.summary = %Q{Set up any project to use AR migrations}
|
9
|
+
gem.description = %Q{Generates a directory structure and assets to allow for using Active Record migrations within any project, Groovy, C\#, etc.}
|
10
|
+
gem.email = "jason@lookforwardenterprises.com"
|
11
|
+
gem.homepage = "http://github.com/midas/migratification"
|
12
|
+
gem.authors = ["C. Jason Harrelson midas"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "migratification #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/bin/migratify
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'ftools'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: #{File.basename($0)} [path]"
|
9
|
+
|
10
|
+
opts.on("-h", "--help", "Displays this help info") do
|
11
|
+
puts opts
|
12
|
+
exit 0
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on('--grails', "Include the groovy/grails specific rake tasks.") { |val| options[:grails] = val }
|
16
|
+
#opts.on('--csharp', "Include the groovy/grails specific rake tasks.") { |val| options[:grails] = val }
|
17
|
+
|
18
|
+
begin
|
19
|
+
opts.parse!(ARGV)
|
20
|
+
rescue OptionParser::ParseError => e
|
21
|
+
warn e.message
|
22
|
+
puts opts
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if ARGV.empty?
|
28
|
+
abort "Please specify the directory to migratify, e.g. `#{File.basename($0)} .'"
|
29
|
+
elsif !File.exists?(ARGV.first)
|
30
|
+
abort "`#{ARGV.first}' does not exist."
|
31
|
+
elsif !File.directory?(ARGV.first)
|
32
|
+
abort "`#{ARGV.first}' is not a directory."
|
33
|
+
elsif ARGV.length > 1
|
34
|
+
abort "Too many arguments; please specify only the directory to migratifu."
|
35
|
+
end
|
36
|
+
|
37
|
+
def unindent(string)
|
38
|
+
indentation = string[/\A\s*/]
|
39
|
+
string.strip.gsub(/^#{indentation}/, "")
|
40
|
+
end
|
41
|
+
|
42
|
+
dirs = [ 'db','db/migrate', 'db/config', 'rake' ]
|
43
|
+
|
44
|
+
files = {
|
45
|
+
"Rakefile" => unindent(<<-FILE),
|
46
|
+
require 'rake'
|
47
|
+
Dir[ 'rake/**/*.rake' ].each { |rake| load rake }
|
48
|
+
|
49
|
+
task :default do
|
50
|
+
warn "\n[warn] You must specify a rake task to run\n"
|
51
|
+
end
|
52
|
+
FILE
|
53
|
+
}
|
54
|
+
|
55
|
+
gem_which_loc = ""
|
56
|
+
gem_name = "migratification"
|
57
|
+
IO.popen( 'gem which migratification' ) { |f| gem_which_loc = f.gets }
|
58
|
+
#gem_which_loc = `gem which migratification`
|
59
|
+
|
60
|
+
puts "\njason"
|
61
|
+
puts "\n\nlocation: #{gem_which_loc}"
|
62
|
+
|
63
|
+
gem_which_loc.gsub!( /\n/, '' )
|
64
|
+
gem_which_loc.gsub!( /\/lib\/#{gem_name}.rb/, '' ) if gem_which_loc =~ /\/lib\/#{gem_name}.rb/
|
65
|
+
gem_which_loc.gsub!( /#{gem_name}.rb/, '' ) if gem_which_loc =~ /#{gem_name}.rb/
|
66
|
+
|
67
|
+
puts "\nCreating directories..."
|
68
|
+
|
69
|
+
# Create the directories
|
70
|
+
dirs.each do |dir|
|
71
|
+
if File.exists?(dir)
|
72
|
+
warn "[skip] `#{dir}' already exists"
|
73
|
+
elsif File.exists?(dir.downcase)
|
74
|
+
warn "[skip] `#{dir.downcase}' exists, which could conflict with `#{file}'"
|
75
|
+
else
|
76
|
+
puts "[create] directory `#{dir}'"
|
77
|
+
FileUtils.mkdir_p( dir )
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
puts "\nCreating Rakefile..."
|
82
|
+
|
83
|
+
# Create the files
|
84
|
+
base = ARGV.shift
|
85
|
+
files.each do |file, content|
|
86
|
+
file = File.join(base, file)
|
87
|
+
if File.exists?(file)
|
88
|
+
warn "[skip] `#{file}' already exists"
|
89
|
+
elsif File.exists?(file.downcase)
|
90
|
+
warn "[skip] `#{file.downcase}' exists, which could conflict with `#{file}'"
|
91
|
+
elsif !File.exists?(File.dirname(file))
|
92
|
+
warn "[skip] directory `#{File.dirname(file)}' does not exist"
|
93
|
+
else
|
94
|
+
puts "[add] writing `#{file}'"
|
95
|
+
File.open(file, "w") { |f| f.write(content) }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
puts "\nCopying resources..."
|
100
|
+
|
101
|
+
# Copy the other files
|
102
|
+
Dir["#{gem_which_loc}/resources/rake/all/**/*.rake"].each do |file|
|
103
|
+
file_path = File.join( base, "rake", File.basename( file ) )
|
104
|
+
|
105
|
+
if File.exists?(file_path)
|
106
|
+
warn "[skip] `#{file_path}' already exists"
|
107
|
+
elsif File.exists?(file_path.downcase)
|
108
|
+
warn "[skip] `#{file_path.downcase}' exists, which could conflict with `#{file}'"
|
109
|
+
elsif !File.exists?(File.dirname(file_path))
|
110
|
+
warn "[skip] directory `#{File.dirname(file_path)}' does not exist"
|
111
|
+
else
|
112
|
+
puts "[add] writing `#{file_path}'"
|
113
|
+
File.copy( file, file_path, false )
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
if options[:grails] == true
|
118
|
+
file_name = "grails.rake"
|
119
|
+
file_path = File.join( base, "rake", file_name )
|
120
|
+
puts "[add] writing `#{file_path}'"
|
121
|
+
FileUtils.copy( File.join( gem_which_loc, "resources", "rake", "optional", file_name ), file_path )
|
122
|
+
end
|
123
|
+
|
124
|
+
puts "\n[done] migratified!\n\n"
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{migratification}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["C. Jason Harrelson midas"]
|
12
|
+
s.date = %q{2010-01-25}
|
13
|
+
s.default_executable = %q{migratify}
|
14
|
+
s.description = %q{Generates a directory structure and assets to allow for using Active Record migrations within any project, Groovy, C#, etc.}
|
15
|
+
s.email = %q{jason@lookforwardenterprises.com}
|
16
|
+
s.executables = ["migratify"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"History.txt",
|
25
|
+
"LICENSE",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"bin/migratify",
|
30
|
+
"lib/migratification.rb",
|
31
|
+
"migratification.gemspec",
|
32
|
+
"resources/rake/all/db.rake",
|
33
|
+
"resources/rake/optional/grails.rake",
|
34
|
+
"spec/migratification_spec.rb",
|
35
|
+
"spec/spec.opts",
|
36
|
+
"spec/spec_helper.rb"
|
37
|
+
]
|
38
|
+
s.homepage = %q{http://github.com/midas/migratification}
|
39
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = %q{1.3.5}
|
42
|
+
s.summary = %q{Set up any project to use AR migrations}
|
43
|
+
s.test_files = [
|
44
|
+
"spec/migratification_spec.rb",
|
45
|
+
"spec/spec_helper.rb"
|
46
|
+
]
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
|
+
s.specification_version = 3
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
53
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require'active_record'
|
3
|
+
require'active_support'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
namespace :db do
|
7
|
+
|
8
|
+
desc "Migrate the database through scripts in db/migrate, targeting specific version with VERSION=x when necessary."
|
9
|
+
task :migrate => :environment do
|
10
|
+
ActiveRecord::Migrator.migrate( 'db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
|
11
|
+
end
|
12
|
+
|
13
|
+
# Set up the ActiveRecord environment
|
14
|
+
task :environment, [:env] do
|
15
|
+
env = ENV['ENV']
|
16
|
+
env = 'development' if env.nil?
|
17
|
+
yaml_file_name = File.join(File.dirname(__FILE__), "..", "db", "config", "database.yml")
|
18
|
+
|
19
|
+
if File.exists?( yaml_file_name )
|
20
|
+
config = YAML::load( File.open( yaml_file_name ) )
|
21
|
+
else
|
22
|
+
abort "\n[abort] You need to create the #{yaml_file_name}. If you are using Grails, try the grails:make_db_yml task.\n\n"
|
23
|
+
end
|
24
|
+
|
25
|
+
ActiveRecord::Base.establish_connection( config[ env ] )
|
26
|
+
ActiveRecord::Base.logger = Logger.new( File.open( File.join( File.dirname( __FILE__ ), "..", "db", "database.log" ), 'a' ) )
|
27
|
+
end
|
28
|
+
|
29
|
+
namespace :gen do
|
30
|
+
|
31
|
+
desc "Generates a new migration file with the NAME variable provided by user."
|
32
|
+
task :migration, [:name] do |t, args|
|
33
|
+
name = args.name
|
34
|
+
#name = ENV['NAME']
|
35
|
+
abort "\n[abort] You must supply a name for you new migration class with the :name parameter." if name.nil?
|
36
|
+
|
37
|
+
migration_dir = File.join( File.dirname( __FILE__ ), "..", "db", "migrate" )
|
38
|
+
|
39
|
+
# Check for files with the same name part (without timestamp considered)
|
40
|
+
files = Dir.new( migration_dir ).entries
|
41
|
+
files.each do |f|
|
42
|
+
unless File.directory?( f )
|
43
|
+
abort "\n[abort] The name '#{name}' is already used in the migration '#{f}'. Please choose another name.\n\n" if f.include?( name )
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
timestamp = DateTime.now.to_formatted_s( :number )
|
48
|
+
mig_file_name = "#{timestamp}_#{name}.rb"
|
49
|
+
mig_file_path = File.join( migration_dir, mig_file_name )
|
50
|
+
|
51
|
+
content = <<-FILE
|
52
|
+
class #{name.camelize} < ActiveRecord::Migration
|
53
|
+
def self.up
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.down
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
FILE
|
62
|
+
|
63
|
+
puts "\n[add] Creating file #{mig_file_path}\n\n"
|
64
|
+
|
65
|
+
File.open( mig_file_path, "w" ) { |f| f.write( content ) }
|
66
|
+
end
|
67
|
+
|
68
|
+
desc "Generates a new create table migration using the TABLE variable specified by the user to create the name of the migration."
|
69
|
+
task :create, [:table] do |t, args|
|
70
|
+
|
71
|
+
table = args.table
|
72
|
+
abort "\n[abort] You must supply a name for you new migration class with the :table parameter." if table.nil?
|
73
|
+
name = "create_#{table.downcase}"
|
74
|
+
|
75
|
+
migration_dir = File.join( File.dirname( __FILE__ ), "..", "db", "migrate" )
|
76
|
+
|
77
|
+
# Check for files with the same name part (without timestamp considered)
|
78
|
+
files = Dir.new( migration_dir ).entries
|
79
|
+
files.each do |f|
|
80
|
+
unless File.directory?( f )
|
81
|
+
abort "\n[abort] The name '#{name}' is already used in the migration '#{f}'. Please choose another name.\n\n" if f.include?( name )
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
timestamp = DateTime.now.to_formatted_s( :number )
|
86
|
+
mig_file_name = "#{timestamp}_#{name}.rb"
|
87
|
+
mig_file_path = File.join( migration_dir, mig_file_name )
|
88
|
+
|
89
|
+
content = <<-FILE
|
90
|
+
class #{name.camelize} < ActiveRecord::Migration
|
91
|
+
def self.up
|
92
|
+
create_table :#{table} do |t|
|
93
|
+
|
94
|
+
t.integer :lock_version, :default => 0
|
95
|
+
t.timestamps
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.down
|
100
|
+
drop_table :#{table}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
FILE
|
104
|
+
|
105
|
+
puts "\n[add] Creating file #{mig_file_path}\n\n"
|
106
|
+
|
107
|
+
File.open( mig_file_path, "w" ) { |f| f.write( content ) }
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
namespace :grails do
|
2
|
+
|
3
|
+
namespace :db do
|
4
|
+
|
5
|
+
desc "Generates a database.yml file from the Grails DataSource.groovy file."
|
6
|
+
task :make_yml do
|
7
|
+
|
8
|
+
grails_db_name = File.join(File.dirname(__FILE__), "..", "grails-app", "conf", "DataSource.groovy")
|
9
|
+
yaml_file_name = File.join(File.dirname(__FILE__), "..", "db", "config", "database.yml")
|
10
|
+
# abort "\nThe Grails #{grails_db_name} file does not exist.\n\n" unless File.exists?( grails_db_name )
|
11
|
+
# abort "\nThe #{yaml_file_name} already exists. Please remove it if you wish to generate a new one.\n\n" if File.exists?( yaml_file_name )
|
12
|
+
#
|
13
|
+
# found_ds = false
|
14
|
+
#
|
15
|
+
# File.open( grails_db_name ) do |file|
|
16
|
+
# while line = file.gets
|
17
|
+
#
|
18
|
+
# if line =~ /dataSource {/
|
19
|
+
# found_ds
|
20
|
+
# elsif found_ds && line =~ /driverClassName/
|
21
|
+
# if line =~ /mysql/
|
22
|
+
# provider = "mysql"
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
|
29
|
+
provider = "mysql"
|
30
|
+
db = {
|
31
|
+
'development' => {
|
32
|
+
'database' => "ticket_system_development",
|
33
|
+
'username' => "ticket_system",
|
34
|
+
'password' => "iberon",
|
35
|
+
'adapter' => provider,
|
36
|
+
'host' => "localhost",
|
37
|
+
'socket' => "/opt/local/var/run/mysql5/mysqld.sock",
|
38
|
+
'encoding' => "UTF8"
|
39
|
+
},
|
40
|
+
'test' => {
|
41
|
+
'database' => "ticket_system_test",
|
42
|
+
'username' => "ticket_system",
|
43
|
+
'password' => "iberon",
|
44
|
+
'adapter' => provider,
|
45
|
+
'host' => "localhost",
|
46
|
+
'socket' => "/opt/local/var/run/mysql5/mysqld.sock",
|
47
|
+
'encoding' => "UTF8"
|
48
|
+
},
|
49
|
+
'production' => {
|
50
|
+
'database' => "ticket_system_production",
|
51
|
+
'username' => "ticket_system",
|
52
|
+
'password' => "iberon",
|
53
|
+
'adapter' => provider,
|
54
|
+
'host' => "localhost",
|
55
|
+
'socket' => "/opt/local/var/run/mysql5/mysqld.sock",
|
56
|
+
'encoding' => "UTF8"
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
content = YAML::dump( db )
|
61
|
+
|
62
|
+
#indentation = content[/\A\s*/]
|
63
|
+
#content.strip.gsub(/^#{indentation}/, "")
|
64
|
+
|
65
|
+
dashes = /--- \n/
|
66
|
+
content.gsub!( dashes, "" )
|
67
|
+
|
68
|
+
File.open( yaml_file_name, "w" ) { |f| f.write( content ) }
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
namespace :gen do
|
73
|
+
|
74
|
+
desc "Generates a new Grails create table migration using the TABLE variable specified by the user to create the name of the migration."
|
75
|
+
task :create do
|
76
|
+
|
77
|
+
table = ENV['TABLE']
|
78
|
+
abort "\n[abort] You must supply a name for you new migration class with the TABLE variable. Usage 'TABLE=users'.\n\n" if table.nil?
|
79
|
+
name = "create_#{table.downcase}"
|
80
|
+
|
81
|
+
migration_dir = File.join( File.dirname( __FILE__ ), "..", "db", "migrate" )
|
82
|
+
|
83
|
+
# Check for files with the same name part (without timestamp considered)
|
84
|
+
files = Dir.new( migration_dir ).entries
|
85
|
+
files.each do |f|
|
86
|
+
unless File.directory?( f )
|
87
|
+
abort "\n[abort] The name '#{name}' is already used in the migration '#{f}'. Please choose another name.\n\n" if f.include?( name )
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
timestamp = DateTime.now.to_formatted_s( :number )
|
92
|
+
mig_file_name = "#{timestamp}_#{name}.rb"
|
93
|
+
mig_file_path = File.join( migration_dir, mig_file_name )
|
94
|
+
|
95
|
+
content = <<-FILE
|
96
|
+
class #{name.camelize} < ActiveRecord::Migration
|
97
|
+
def self.up
|
98
|
+
create_table :#{table} do |t|
|
99
|
+
|
100
|
+
t.integer :version, :default => 0
|
101
|
+
t.timestamps
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.down
|
106
|
+
drop_table :#{table}
|
107
|
+
end
|
108
|
+
end
|
109
|
+
FILE
|
110
|
+
|
111
|
+
puts "\n[add] Creating file #{mig_file_path}\n\n"
|
112
|
+
|
113
|
+
File.open( mig_file_path, "w" ) { |f| f.write( content ) }
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: migratification
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- C. Jason Harrelson midas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-25 00:00:00 -06:00
|
13
|
+
default_executable: migratify
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
description: Generates a directory structure and assets to allow for using Active Record migrations within any project, Groovy, C#, etc.
|
26
|
+
email: jason@lookforwardenterprises.com
|
27
|
+
executables:
|
28
|
+
- migratify
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- History.txt
|
38
|
+
- LICENSE
|
39
|
+
- README.rdoc
|
40
|
+
- Rakefile
|
41
|
+
- VERSION
|
42
|
+
- bin/migratify
|
43
|
+
- lib/migratification.rb
|
44
|
+
- migratification.gemspec
|
45
|
+
- resources/rake/all/db.rake
|
46
|
+
- resources/rake/optional/grails.rake
|
47
|
+
- spec/migratification_spec.rb
|
48
|
+
- spec/spec.opts
|
49
|
+
- spec/spec_helper.rb
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://github.com/midas/migratification
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --charset=UTF-8
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.3.5
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Set up any project to use AR migrations
|
78
|
+
test_files:
|
79
|
+
- spec/migratification_spec.rb
|
80
|
+
- spec/spec_helper.rb
|