legacy_data 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ === EDGE
2
+ *
3
+
4
+ === 0.1.11 2010-03-05
5
+ * Fix for SQLServer and other drivers that do not support constraints
6
+
7
+ === 0.1.10 2009-10-05
8
+ * Initial release
data/README.md CHANGED
@@ -10,21 +10,21 @@ information encoded in it.
10
10
 
11
11
  - To generate an ActiveRecord model for each table in the database just type
12
12
 
13
- `script/generate script/generate models_from_tables`
13
+ `script/generate models_from_tables`
14
14
 
15
15
  - If you don't want all tables in the database tell it which table to model
16
16
 
17
- `script/generate script/generate models_from_tables --table-name comments`
17
+ `script/generate models_from_tables --table-name comments`
18
18
 
19
19
  This uses any foreign_key constraints in the database to spider the database and model the comments table and all associated tables.
20
20
 
21
21
  - If you *really* only want the comments table tell it not to follow any foreign_keys
22
22
 
23
- `script/generate script/generate models_from_tables --table-name comments --skip-associated`
23
+ `script/generate models_from_tables --table-name comments --skip-associated`
24
24
 
25
25
  - If you use [factory girl](http://github.com/thoughtbot/factory_girl) it will generate a simple factory for each model it generates
26
26
 
27
- `script/generate script/generate models_from_tables --table-name comments --with-factories`
27
+ `script/generate models_from_tables --table-name comments --with-factories`
28
28
 
29
29
  (You do need to install the plugin `gem install legacy_data` as long as http://gemcutter.org is one of your gem sources)
30
30
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.10
1
+ 0.1.11
@@ -3,23 +3,25 @@ require File.dirname(__FILE__) + '/../../lib/legacy_data'
3
3
  class ModelsFromTablesGenerator < Rails::Generator::Base
4
4
  def manifest
5
5
  record do |m|
6
- m.directory File.join('app/models')
7
-
8
6
  LegacyData::TableClassNameMapper.naming_convention = options[:table_naming_convention]
9
7
 
10
8
  analyzed_tables = LegacyData::Schema.analyze(options)
11
9
 
12
- LegacyData::TableClassNameMapper.let_user_validate_dictionary
10
+ unless analyzed_tables.blank?
11
+ m.directory File.join('app/models')
12
+
13
+ LegacyData::TableClassNameMapper.let_user_validate_dictionary
13
14
 
14
- analyzed_tables.each do |analyzed_table|
15
- analyzed_table.class_name = LegacyData::TableClassNameMapper.class_name_for(analyzed_table[:table_name])
15
+ analyzed_tables.each do |analyzed_table|
16
+ analyzed_table.class_name = LegacyData::TableClassNameMapper.class_name_for(analyzed_table[:table_name])
16
17
 
17
- m.class_collisions :class_path, analyzed_table[:class_name]
18
- m.template 'model.rb',
19
- File.join('app/models', "#{analyzed_table[:class_name].underscore}.rb"),
20
- :assigns => {:definition => analyzed_table}
18
+ m.class_collisions :class_path, analyzed_table[:class_name]
19
+ m.template 'model.rb',
20
+ File.join('app/models', "#{analyzed_table[:class_name].underscore}.rb"),
21
+ :assigns => {:definition => analyzed_table}
21
22
 
22
- add_factory_girl_factory analyzed_table if options[:with_factories]
23
+ add_factory_girl_factory analyzed_table if options[:with_factories]
24
+ end
23
25
 
24
26
  end
25
27
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{legacy_data}
8
- s.version = "0.1.10"
8
+ s.version = "0.1.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex Rothenberg"]
12
- s.date = %q{2009-11-05}
12
+ s.date = %q{2010-03-05}
13
13
  s.description = %q{Create ActiveRecord models from an existing database}
14
14
  s.email = %q{alex@alexrothenberg.com}
15
15
  s.extra_rdoc_files = [
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".document",
21
21
  ".gitignore",
22
+ "History.txt",
22
23
  "LICENSE",
23
24
  "README.md",
24
25
  "Rakefile",
@@ -134,11 +135,10 @@ Gem::Specification.new do |s|
134
135
  "spec/models_from_tables_generator_spec.rb",
135
136
  "spec/spec_helper.rb"
136
137
  ]
137
- s.has_rdoc = true
138
138
  s.homepage = %q{http://github.com/alexrothenberg/legacy_data}
139
139
  s.rdoc_options = ["--charset=UTF-8"]
140
140
  s.require_paths = ["lib"]
141
- s.rubygems_version = %q{1.3.2}
141
+ s.rubygems_version = %q{1.3.6}
142
142
  s.summary = %q{Create ActiveRecord models from an existing database}
143
143
  s.test_files = [
144
144
  "spec/expected/factories.rb",
@@ -26,7 +26,11 @@ module LegacyData
26
26
  def self.initialize_tables(table_name)
27
27
  clear_table_definitions
28
28
  if table_name
29
- add_pending_table(table_name)
29
+ if connection.table_exists? table_name
30
+ add_pending_table(table_name)
31
+ else
32
+ log "Warning: Table '#{table_name}' does not exist"
33
+ end
30
34
  else
31
35
  self.tables.each {|table| add_pending_table(table) }
32
36
  end
@@ -181,7 +185,7 @@ module LegacyData
181
185
  end
182
186
 
183
187
  def custom_constraints
184
- return [] unless connection.respond_to? :constraints
188
+ return [[],[]] unless connection.respond_to? :constraints
185
189
  custom_constraints, inclusion_constraints = {}, {}
186
190
  connection.constraints(table_name).each do |constraint|
187
191
  constraint_sql = constraint.second
@@ -1,12 +1,46 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe LegacyData::Schema do
4
+ describe 'which tables to start with' do
5
+ it 'should start with all tables when no parameter limits us' do
6
+ LegacyData::Schema.should_receive(:tables).and_return ['table1', 'table2']
7
+ LegacyData::Schema.initialize_tables(nil)
8
+
9
+ LegacyData::Schema.table_definitions.keys.should == ['table1', 'table2']
10
+ end
11
+
12
+ it 'should start with one table when we pass a valid table name in' do
13
+ LegacyData::Schema.stub!(:connection=>connection=mock)
14
+ connection.should_receive(:table_exists?).with('specific_table').and_return(true)
15
+
16
+ LegacyData::Schema.initialize_tables('specific_table')
17
+
18
+ LegacyData::Schema.table_definitions.keys.should == ['specific_table']
19
+ end
20
+
21
+ it 'should start with no tableswhen we pass an invalid table name in' do
22
+ LegacyData::Schema.should_receive(:puts).with("Warning: Table 'specific_table' does not exist")
23
+ LegacyData::Schema.stub!(:connection=>connection=mock)
24
+ connection.should_receive(:table_exists?).with('specific_table').and_return(false)
25
+
26
+ LegacyData::Schema.initialize_tables('specific_table')
27
+
28
+ LegacyData::Schema.table_definitions.keys.should == []
29
+ end
30
+ end
31
+
4
32
  describe 'following associations' do
5
33
  before :each do
34
+ LegacyData::Schema.stub!(:connection=>connection=mock)
35
+ connection.stub!(:table_exists?).with('posts' ).and_return(true)
36
+ connection.stub!(:table_exists?).with('comments').and_return(true)
37
+
6
38
  LegacyData::Schema.stub!(:analyze_table).with('posts' ).and_return(@posts_analysis =mock(:posts, {:join_table? =>false}))
7
39
  LegacyData::Schema.stub!(:analyze_table).with('comments').and_return(@comments_analysis=mock(:comments, {:join_table? =>false}))
8
- @posts_analysis.stub!( :[]).with(:relations).and_return({:belongs_to=>{ }, :has_many=>{:comments=>{:foreign_key=>:posts_id}}})
9
- @comments_analysis.stub!(:[]).with(:relations).and_return({:belongs_to=>{:posts=>{:foreign_key=>:posts_id}}, :has_many=>{ }})
40
+ @posts_analysis.stub!( :[]).with(:relations).and_return({:belongs_to=>{ },
41
+ :has_many=>{:comments=>{:foreign_key=>:posts_id}}})
42
+ @comments_analysis.stub!(:[]).with(:relations).and_return({:belongs_to=>{:posts=>{:foreign_key=>:posts_id}},
43
+ :has_many=>{ }})
10
44
  end
11
45
 
12
46
  it 'should analyze all tables when not given a table to start with' do
@@ -170,7 +204,7 @@ describe LegacyData::Schema do
170
204
 
171
205
  it 'should give no custom constraints when the adapter does not support it' do
172
206
  @connection.should_receive(:respond_to?).with(:constraints).and_return(false)
173
- @schema.custom_constraints.should == []
207
+ @schema.custom_constraints.should == [[],[]]
174
208
  end
175
209
 
176
210
  describe 'custom constraints' do
@@ -54,7 +54,7 @@ describe LegacyData::TableDefinition do
54
54
  table_definition = LegacyData::TableDefinition.new(:constraints => {:custom => {:my_constraint => "some plsql logic",
55
55
  :another_one => "multi\nline\n plsql logic"}
56
56
  })
57
- table_definition.custom_constraints_to_s.should include <<-RB
57
+ table_definition.custom_constraints_to_s.should include(<<-RB )
58
58
  validate :validate_my_constraint
59
59
  def validate_my_constraint
60
60
  # TODO: validate this SQL constraint
@@ -63,7 +63,7 @@ describe LegacyData::TableDefinition do
63
63
  SQL
64
64
  end
65
65
  RB
66
- table_definition.custom_constraints_to_s.should include <<-RB
66
+ table_definition.custom_constraints_to_s.should include(<<-RB)
67
67
  validate :validate_another_one
68
68
  def validate_another_one
69
69
  # TODO: validate this SQL constraint
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require 'activerecord'
2
+ require 'active_record'
3
3
  # require 'active_record/connection_adapters/oracle_enhanced_adapter'
4
4
 
5
5
 
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legacy_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 11
9
+ version: 0.1.11
5
10
  platform: ruby
6
11
  authors:
7
12
  - Alex Rothenberg
@@ -9,39 +14,47 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-11-05 00:00:00 -05:00
17
+ date: 2010-03-05 00:00:00 -05:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rspec
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
23
29
  version: "0"
24
- version:
30
+ type: :development
31
+ version_requirements: *id001
25
32
  - !ruby/object:Gem::Dependency
26
33
  name: activerecord
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - ">="
32
38
  - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
33
41
  version: "0"
34
- version:
42
+ type: :runtime
43
+ version_requirements: *id002
35
44
  - !ruby/object:Gem::Dependency
36
45
  name: matthuhiggins-foreigner
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
40
48
  requirements:
41
49
  - - ">="
42
50
  - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ - 2
54
+ - 1
43
55
  version: 0.2.1
44
- version:
56
+ type: :runtime
57
+ version_requirements: *id003
45
58
  description: Create ActiveRecord models from an existing database
46
59
  email: alex@alexrothenberg.com
47
60
  executables: []
@@ -54,6 +67,7 @@ extra_rdoc_files:
54
67
  files:
55
68
  - .document
56
69
  - .gitignore
70
+ - History.txt
57
71
  - LICENSE
58
72
  - README.md
59
73
  - Rakefile
@@ -181,18 +195,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
195
  requirements:
182
196
  - - ">="
183
197
  - !ruby/object:Gem::Version
198
+ segments:
199
+ - 0
184
200
  version: "0"
185
- version:
186
201
  required_rubygems_version: !ruby/object:Gem::Requirement
187
202
  requirements:
188
203
  - - ">="
189
204
  - !ruby/object:Gem::Version
205
+ segments:
206
+ - 0
190
207
  version: "0"
191
- version:
192
208
  requirements: []
193
209
 
194
210
  rubyforge_project:
195
- rubygems_version: 1.3.2
211
+ rubygems_version: 1.3.6
196
212
  signing_key:
197
213
  specification_version: 3
198
214
  summary: Create ActiveRecord models from an existing database