rosewood_migrations 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +52 -0
- data/Readme.md +10 -0
- data/lib/rosewood_migrations.rb +50 -0
- data/lib/rosewood_migrations/version.rb +3 -0
- data/rosewood_migrations.gemspec +22 -0
- metadata +72 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
# duplicate the existing Rails db:migrate stuff, with just a few key changes. as an aside, I
|
5
|
+
# wish I had time to refactor this shit, because my God, this is a lot of copy-and-paste for
|
6
|
+
# the benefit of a very small number of actual changes. specifically, eleven total characters
|
7
|
+
# in five lines of code.
|
8
|
+
|
9
|
+
db_namespace = namespace :db do
|
10
|
+
namespace :migrate do
|
11
|
+
desc 'Display status of migrations'
|
12
|
+
task :status => [:environment, :load_config] do
|
13
|
+
config = ActiveRecord::Base.configurations[Rails.env || 'development']
|
14
|
+
ActiveRecord::Base.establish_connection(config)
|
15
|
+
unless ActiveRecord::Base.connection.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name)
|
16
|
+
puts 'Schema migrations table does not exist yet.'
|
17
|
+
next # means "return" for rake task
|
18
|
+
end
|
19
|
+
db_list = ActiveRecord::Base.connection.select_values("SELECT version FROM #{ActiveRecord::Migrator.schema_migrations_table_name}")
|
20
|
+
file_list = []
|
21
|
+
Dir.foreach(File.join(Rails.root, 'db', 'migrate')) do |file|
|
22
|
+
# first change: the next three lines of actual code represent 60% of all
|
23
|
+
# deviations from the original code in this file.
|
24
|
+
#
|
25
|
+
# old and busted:
|
26
|
+
# only files matching "20091231235959_some_name.rb" pattern
|
27
|
+
# new hotness:
|
28
|
+
# only files matching "some_name_20091231235959.rb" pattern
|
29
|
+
if match_data = /^(.+)_(\d{14})\.rb$/.match(file)
|
30
|
+
status = db_list.delete(match_data[2]) ? 'up' : 'down'
|
31
|
+
file_list << [status, match_data[2], match_data[1].humanize]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
db_list.map! do |version|
|
35
|
+
['up', version, '********** NO FILE **********']
|
36
|
+
end
|
37
|
+
# output
|
38
|
+
puts "\ndatabase: #{config['database']}\n\n"
|
39
|
+
puts "#{'Status'.center(8)} #{'Migration ID'.ljust(14)} Migration Name"
|
40
|
+
puts "-" * 50
|
41
|
+
|
42
|
+
# behold, the remaining 40% of all deviations from the original code occur in the
|
43
|
+
# next two lines, where we swap migration[2] with migration[1] repeatedly. to be
|
44
|
+
# clear, that's measured in lines of code, not characters.
|
45
|
+
(db_list + file_list).sort_by {|migration| migration[2]}.each do |migration|
|
46
|
+
puts "#{migration[0].center(8)} #{migration[2].ljust(14)} #{migration[1]}"
|
47
|
+
end
|
48
|
+
puts
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
data/Readme.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
Rosewood Migrations
|
2
|
+
===================
|
3
|
+
|
4
|
+
When I was a kid, my dad raced a vintage Jaguar. We would go to vintage British car meetups and I'd check out the beautiful old Bentleys and Rolls Royces. In the economic boom of the late 80s, my dad began brokering vintage cars, mostly selling them from sellers in America and Europe to buyers in Japan. I got to see and sit in a lot of beautiful old Jags, Bentleys, and Rollses, all of which had lovely interiors with wood, leather, and brass - and many of which had dining trays in the backseats, like on an airplane.
|
5
|
+
|
6
|
+
I don't know why we in the Rails community have ignored the wonderful luxury of tab completion for such a long time when it comes to our migrations, but I for one am simply too experienced to tolerate the pitiful limping Yugo of 20111234980701987234098712_filename.rb when I could help myself to the graceful, sophisticated comfort of filename_20118175098237401981982734098172304987109872341, which is more amenable to tab-completion and thus easier to use.
|
7
|
+
|
8
|
+
Likewise, I use bash, and it's very, very rare that I have to type a filename at all, because when I'm not tab-completing my way through the entire filename based on only a few characters, I'm using special variables like !$ and !!. Consequently, actually clicking and dragging to copy a migration filename feels like reading by candlelight in the age of electricity. There's simply no call for such primitive nonsense on an operating system like OS X, which makes it trivial to deposit filenames into your copy/paste buffer automatically.
|
9
|
+
|
10
|
+
Good day, sir.
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Rails
|
2
|
+
module Generators
|
3
|
+
module Migration
|
4
|
+
# Creates a migration template at the given destination. The difference
|
5
|
+
# to the default template method is that the migration version is appended
|
6
|
+
# to the destination file name.
|
7
|
+
#
|
8
|
+
# The migration version, migration file name, migration class name are
|
9
|
+
# available as instance variables in the template to be rendered.
|
10
|
+
#
|
11
|
+
# This version of the method is monkey-patched to implement two improvements.
|
12
|
+
# First, the filename ends in a string of digits representing a timestamp -
|
13
|
+
# normally in a Rails migration the filename *begins* with that string. This
|
14
|
+
# allows us to use Unix tab-completion. Second, the migration filename is
|
15
|
+
# automatically copied into the OS X copy/paste or "clipboard" buffer. This
|
16
|
+
# feature is not supported on other operating systems and this gem might not
|
17
|
+
# work on other operating systems.
|
18
|
+
#
|
19
|
+
# ==== Examples
|
20
|
+
#
|
21
|
+
# migration_template "migration.rb", "db/migrate/add_foo_to_bar.rb"
|
22
|
+
#
|
23
|
+
def migration_template(source, destination=nil, config={})
|
24
|
+
destination = File.expand_path(destination || source, self.destination_root)
|
25
|
+
|
26
|
+
migration_dir = File.dirname(destination)
|
27
|
+
@migration_number = self.class.next_migration_number(migration_dir)
|
28
|
+
@migration_file_name = File.basename(destination).sub(/\.rb$/, '')
|
29
|
+
@migration_class_name = @migration_file_name.camelize
|
30
|
+
|
31
|
+
destination = self.class.migration_exists?(migration_dir, @migration_file_name)
|
32
|
+
|
33
|
+
if !(destination && options[:skip]) && behavior == :invoke
|
34
|
+
if destination && options.force?
|
35
|
+
remove_file(destination)
|
36
|
+
elsif destination
|
37
|
+
raise Error, "Another migration is already named #{@migration_file_name}: #{destination}"
|
38
|
+
end
|
39
|
+
# These next two lines of code represent the sum total of all deviations from the
|
40
|
+
# the original code base contained within this particular file.
|
41
|
+
destination = File.join(migration_dir, "#{@migration_number}_#{@migration_file_name}.rb")
|
42
|
+
system("printf #{destination} | pbcopy")
|
43
|
+
end
|
44
|
+
|
45
|
+
template(source, destination, config)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rosewood_migrations/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rosewood_migrations"
|
7
|
+
s.version = RosewoodMigrations::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Giles Bowkett"]
|
10
|
+
s.email = ["gilesb@gmail.com"]
|
11
|
+
s.homepage = "http://www.youtube.com/watch?v=G_pGT8Q_tjk"
|
12
|
+
s.summary = %q{Pardon me. Do you have any Grey Poupon?}
|
13
|
+
s.description = %q{Smooth, uninterrupted comfort.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "rosewood_migrations"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
22
|
+
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rosewood_migrations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Giles Bowkett
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-16 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Smooth, uninterrupted comfort.
|
22
|
+
email:
|
23
|
+
- gilesb@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- Gemfile
|
33
|
+
- Rakefile
|
34
|
+
- Readme.md
|
35
|
+
- lib/rosewood_migrations.rb
|
36
|
+
- lib/rosewood_migrations/version.rb
|
37
|
+
- rosewood_migrations.gemspec
|
38
|
+
homepage: http://www.youtube.com/watch?v=G_pGT8Q_tjk
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
hash: 3
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
version: "0"
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project: rosewood_migrations
|
67
|
+
rubygems_version: 1.8.3
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Pardon me. Do you have any Grey Poupon?
|
71
|
+
test_files: []
|
72
|
+
|