data_transformation 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +16 -0
- data/data_transformation.gemspec +4 -4
- data/lib/data_transformation/schema.rb +8 -8
- data/lib/data_transformation/transformation.rb +5 -5
- data/lib/data_transformation/transformer.rb +27 -27
- data/lib/data_transformation/version.rb +1 -1
- data/lib/data_transformation.rb +5 -5
- data/lib/generators/transform/templates/transform.rb +2 -2
- data/lib/tasks/data_transformations.rake +29 -29
- metadata +21 -21
data/README
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## Installing the Transformer ##
|
2
|
+
Add it as a hook to your existing rake tasks in Rakefile
|
3
|
+
|
4
|
+
Rake::Task['db:schema:load'].enhance do
|
5
|
+
Rake::Task['db:transform:load'].invoke
|
6
|
+
end
|
7
|
+
|
8
|
+
Rake::Task['db:schema:dump'].enhance do
|
9
|
+
Rake::Task['db:transform:dump'].invoke
|
10
|
+
end
|
11
|
+
|
12
|
+
Rake::Task['db:migrate'].enhance do
|
13
|
+
Rake::Task['db:transform'].invoke
|
14
|
+
end
|
15
|
+
|
16
|
+
|
1
17
|
## Using the Transformer ##
|
2
18
|
|
3
19
|
It's just like migrating, moreso than you probably originally thought.
|
data/data_transformation.gemspec
CHANGED
@@ -20,9 +20,9 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
21
|
s.require_path = "lib"
|
22
22
|
|
23
|
-
s.add_dependency "activerecord"
|
24
|
-
s.add_development_dependency "bundler"
|
25
|
-
s.add_development_dependency "rspec"
|
26
|
-
s.add_development_dependency "generator_spec"
|
23
|
+
s.add_dependency "activerecord"
|
24
|
+
s.add_development_dependency "bundler"
|
25
|
+
s.add_development_dependency "rspec"
|
26
|
+
s.add_development_dependency "generator_spec"
|
27
27
|
s.add_development_dependency "sqlite3"
|
28
28
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module DataTransformation
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
2
|
+
class Schema < DataTransformation::Transformation
|
3
|
+
def self.define(info={})
|
4
|
+
unless info[:version].blank?
|
5
|
+
initialize_schema_migrations_table
|
6
|
+
ActiveRecord::Base.connection.assume_migrated_upto_version(info[:version], DataTransformation::Transformer.migrations_path)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
10
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'active_record/migration'
|
2
2
|
|
3
3
|
module DataTransformation
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
class Transformation < ActiveRecord::Migration
|
5
|
+
def transform(direction)
|
6
|
+
migrate(direction)
|
7
|
+
end
|
8
|
+
end
|
9
9
|
end
|
@@ -1,36 +1,36 @@
|
|
1
1
|
require 'active_record/migration'
|
2
2
|
|
3
3
|
module DataTransformation
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
class Transformer < ActiveRecord::Migrator
|
5
|
+
class << self
|
6
|
+
def transform(transforms_path, target_version=nil)
|
7
|
+
migrate(transforms_path, target_version)
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def migrations_path
|
16
|
-
migrations_paths.first
|
17
|
-
end
|
10
|
+
def migrations_paths
|
11
|
+
@migrations_paths ||= ['db/transforms']
|
12
|
+
Array.wrap(@migrations_paths)
|
13
|
+
end
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
def migrations_path
|
16
|
+
migrations_paths.first
|
17
|
+
end
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
def down
|
20
|
+
raise "Unimplemented as a Transformation"
|
21
|
+
end
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
def forward
|
24
|
+
raise "Unimplemented as a Transformation"
|
25
|
+
end
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
def rollback
|
28
|
+
raise "Unimplemented as a Transformation"
|
29
|
+
end
|
30
|
+
|
31
|
+
def schema_migrations_table_name
|
32
|
+
ActiveRecord::Base.table_name_prefix + "schema_transforms" + ActiveRecord::Base.table_name_suffix
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
36
|
end
|
data/lib/data_transformation.rb
CHANGED
@@ -4,9 +4,9 @@ require "data_transformation/transformation"
|
|
4
4
|
require "data_transformation/schema"
|
5
5
|
|
6
6
|
module DataTransformation
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
class Railtie < Rails::Railtie
|
8
|
+
rake_tasks do
|
9
|
+
load 'tasks/data_transformations.rake'
|
10
|
+
end
|
11
|
+
end
|
12
12
|
end
|
@@ -37,42 +37,42 @@ end
|
|
37
37
|
desc "Undoes the hack in Active Record for the migrations"
|
38
38
|
task :undo_hack_in_ar do
|
39
39
|
class << ActiveRecord::Migrator
|
40
|
-
alias_method :schema_migrations_table_name, :original_schema_migrations_table_name
|
40
|
+
alias_method :schema_migrations_table_name, :original_schema_migrations_table_name
|
41
41
|
end
|
42
42
|
|
43
43
|
ActiveRecord::ConnectionAdapters::SchemaStatements.module_eval do
|
44
|
-
alias_method :initialize_schema_migrations_table, :original_initialize_schema_migrations_table
|
44
|
+
alias_method :initialize_schema_migrations_table, :original_initialize_schema_migrations_table
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
namespace :db do
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
desc "Transform the database (options: VERSION=x, VERBOSE=false)."
|
50
|
+
task :transform => [:environment, :hack_in_ar] do
|
51
|
+
DataTransformation::Transformation.verbose = ENV['VERBOSE'] ? ENV['VERBOSE'] == "true" : true
|
52
|
+
DataTransformation::Transformer.transform('db/transforms/', ENV['VERSION'] ? ENV['VERSION'].to_i : nil)
|
53
|
+
Rake::Task["db:transform:dump"].invoke
|
54
|
+
end
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
56
|
+
namespace :transform do
|
57
|
+
desc "Dump the Transform schema."
|
58
|
+
task :dump => [:environment, :hack_in_ar] do
|
59
|
+
filename = ENV['SCHEMA'] || "#{Rails.root}/db/transform_schema.rb"
|
60
|
+
File.open(filename, 'w') do |f|
|
61
|
+
version = DataTransformation::Transformer::current_version rescue nil
|
62
|
+
f.puts "DataTransformation::Schema.define(:version => #{version})"
|
63
|
+
end
|
64
|
+
Rake::Task['undo_hack_in_ar'].invoke
|
65
|
+
end
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
67
|
+
desc "Load the Transform schema."
|
68
|
+
task :load => [:environment, :hack_in_ar] do
|
69
|
+
filename = ENV['SCHEMA'] || "#{Rails.root}/db/transform_schema.rb"
|
70
|
+
if File.exists?(filename)
|
71
|
+
load(filename)
|
72
|
+
else
|
73
|
+
abort %{#{filename} doesn't exist yet. Run 'rake db:transform' to create it and then try again.}
|
74
|
+
end
|
75
|
+
Rake::Task['undo_hack_in_ar'].invoke
|
76
|
+
end
|
77
|
+
end
|
78
78
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_transformation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,55 +9,55 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &70253803662560 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70253803662560
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70253803661600 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
|
-
- -
|
30
|
+
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70253803661600
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70253803661120 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ! '>='
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
43
|
+
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70253803661120
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: generator_spec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70253803660640 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0
|
54
|
+
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70253803660640
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: sqlite3
|
60
|
-
requirement: &
|
60
|
+
requirement: &70253803659840 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70253803659840
|
69
69
|
description: To keep the necessity of changing data out of migrations, transformations
|
70
70
|
keep track of that
|
71
71
|
email:
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: 1.3.6
|
115
115
|
requirements: []
|
116
116
|
rubyforge_project: data_transformation
|
117
|
-
rubygems_version: 1.8.
|
117
|
+
rubygems_version: 1.8.10
|
118
118
|
signing_key:
|
119
119
|
specification_version: 3
|
120
120
|
summary: Rails 3 Data Transformations
|