paraphraser 0.2.3 → 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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 1.0.0
@@ -1,3 +1,5 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'kernel_ext'))
2
+
1
3
  module Paraphraser
2
4
  class Convertor
3
5
 
@@ -10,23 +12,48 @@ module Paraphraser
10
12
  class << self
11
13
 
12
14
  def convert
15
+ exit(0) unless agree_to_proceed?
16
+
17
+ Rake::Task['db:drop'].invoke
18
+ Rake::Task['db:create'].invoke
19
+
13
20
  with_activerecord_stubbed do
21
+ announce "CreateSchemaMigrations"
14
22
  migrations.each do |migration|
15
23
  announce "#{migration.version} : #{migration.name}"
16
24
  migration.migrate(direction)
17
25
  update_schema_migrations_table(migration.version)
18
26
  end
19
27
  end
28
+
29
+ print_without_file_output "\nWe're done! You could either copy the output above or give ./migration.sql for *the dba review*\n\n"
20
30
  end
21
31
 
22
32
  private
23
33
 
34
+ def agree_to_proceed?
35
+ print_without_file_output "\nThe way paraphraser works, it will drop and re-create a database and will output the migration sql in the process.\n" +
36
+ "All data in #{::Rails.configuration.database_configuration[::Rails.env]['database']} at #{::Rails.configuration.database_configuration[::Rails.env]['host'] || 'localhost'} will be wiped-out. proceed? (Y/n): "
37
+ choice = STDIN.gets.chomp
38
+
39
+ case(choice)
40
+ when 'Y' then
41
+ return true
42
+ when 'n', 'no', 'No' then
43
+ print_without_file_output "\nYou can choose to run against a different Rails.env by passing an argument to paraphraser as, rake 'db:paraphrase:all[test]'\n\n"
44
+ return false
45
+ else
46
+ print_without_file_output "\nYour input was neither 'Yes' nor 'n', so exiting.\n\n"
47
+ return false
48
+ end
49
+ end
50
+
24
51
  def connection
25
52
  ActiveRecord::Base.connection
26
53
  end
27
54
 
28
55
  def migrations
29
- @migrations ||= ActiveRecord::Migrator.new(direction, migrations_path).migrations
56
+ @@migrations ||= ActiveRecord::Migrator.new(direction, migrations_path).migrations
30
57
  end
31
58
 
32
59
  def with_activerecord_stubbed(&block)
@@ -36,22 +63,11 @@ module Paraphraser
36
63
  end
37
64
 
38
65
  def apply_overrides
39
- connection.class.send(:define_method, :execute) do |sql, name = nil, skip_logging = false|
40
- print "#{sql};\n"
41
- STDOUT.flush
42
- end
43
- connection.class.send(:define_method, :initialize_schema_migrations_table) { }
44
- connection.class.send(:define_method, :tables) { |*args| [] }
45
- connection.class.send(:define_method, :index_name_exists?) {|*args| false }
46
- connection.class.send(:define_method, :rename_column) do |table_name, column_name, new_column_name|
47
- execute "ALTER TABLE #{quote_table_name(table_name)} RENAME COLUMN #{quote_column_name(column_name)} TO #{quote_column_name(new_column_name)}"
48
- end
49
- connection.class.send(:define_method, :change_column) do |table_name, column_name, type, options = {}|
50
- execute "ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} TYPE #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
51
- end
52
- connection.class.send(:define_method, :change_column_default) do |table_name, column_name, default|
53
- execute "ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} SET DEFAULT #{quote(default)}"
66
+ connection.class.send(:define_method, :execute_with_paraphrasing) do |sql, name = nil|
67
+ print "#{sql};\n" and STDOUT.flush unless sql =~ /^SHOW/
68
+ execute_without_paraphrasing sql, name
54
69
  end
70
+ connection.class.send(:alias_method_chain, :execute, :paraphrasing)
55
71
  end
56
72
 
57
73
  def update_schema_migrations_table(version)
@@ -63,7 +79,6 @@ module Paraphraser
63
79
  print "\n-- %s %s\n" % [text, "-" * length]
64
80
  end
65
81
 
66
- end
67
-
82
+ end
68
83
  end
69
84
  end
@@ -0,0 +1,13 @@
1
+ module Kernel
2
+
3
+ def migration_file
4
+ @@file ||= File.open('migration.sql', 'w')
5
+ end
6
+
7
+ def print_with_file_output(string)
8
+ migration_file.write string
9
+ print_without_file_output(string)
10
+ end
11
+ alias_method_chain :print, :file_output
12
+
13
+ end
@@ -2,14 +2,10 @@ namespace :db do
2
2
  namespace :paraphrase do
3
3
 
4
4
  desc 'provides a rake task to convert all migrations to sql statements for *the dba*.'
5
- task :all => :environment do
5
+ task :all, [:rails_env] => :environment do |t, args|
6
+ Rails.env = args[:rails_env] || 'test'
6
7
  Paraphraser::Convertor.convert
7
8
  end
8
9
 
9
- desc 'provides a rake task to convert all migrations in range to sql statements for *the dba*.'
10
- task :in_range => :environment do
11
- Paraphraser::Convertor.convert
12
- end
13
-
14
10
  end
15
11
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{paraphraser}
8
- s.version = "0.2.3"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Vinay Patel"]
12
- s.date = %q{2010-12-30}
12
+ s.date = %q{2011-01-05}
13
13
  s.description = %q{provides a rake task to convert migrations to sql statements for *the dba*.}
14
14
  s.email = %q{mail@vinayvinay.com}
15
15
  s.extra_rdoc_files = [
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "VERSION",
27
27
  "lib/paraphraser.rb",
28
28
  "lib/paraphraser/convertor.rb",
29
+ "lib/paraphraser/kernel_ext.rb",
29
30
  "lib/paraphraser/railtie.rb",
30
31
  "lib/paraphraser/railties/paraphraser.rake",
31
32
  "paraphraser.gemspec",
metadata CHANGED
@@ -3,10 +3,10 @@ name: paraphraser
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
+ - 1
6
7
  - 0
7
- - 2
8
- - 3
9
- version: 0.2.3
8
+ - 0
9
+ version: 1.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Vinay Patel
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-30 00:00:00 -06:00
17
+ date: 2011-01-05 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -66,6 +66,7 @@ files:
66
66
  - VERSION
67
67
  - lib/paraphraser.rb
68
68
  - lib/paraphraser/convertor.rb
69
+ - lib/paraphraser/kernel_ext.rb
69
70
  - lib/paraphraser/railtie.rb
70
71
  - lib/paraphraser/railties/paraphraser.rake
71
72
  - paraphraser.gemspec
@@ -85,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
86
  requirements:
86
87
  - - ">="
87
88
  - !ruby/object:Gem::Version
88
- hash: -892620163
89
+ hash: 848231213
89
90
  segments:
90
91
  - 0
91
92
  version: "0"