alexrothenberg-legacy_data 0.0.9 → 0.0.10
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/README.rdoc +1 -1
- data/VERSION +1 -1
- data/generators/models_from_tables/templates/model.rb +3 -3
- data/legacy_data.gemspec +2 -2
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +12 -1
- data/lib/legacy_data/schema.rb +1 -1
- data/lib/legacy_data/table_definition.rb +1 -1
- data/spec/legacy_data/schema_spec.rb +4 -2
- data/spec/legacy_data/table_definition_spec.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
|
@@ -24,7 +24,7 @@ Examples:
|
|
|
24
24
|
* Configure your application to connect to your existing Oracle database. Get the connect connect string from your dba (something like: user/password@server.example.com:1541/sid.world) and edit your config/database.yml
|
|
25
25
|
development:
|
|
26
26
|
adapter: oracle_enhanced
|
|
27
|
-
database: server.example.com:1541/
|
|
27
|
+
database: server.example.com:1541/my_database.world
|
|
28
28
|
username: user
|
|
29
29
|
password: password
|
|
30
30
|
* Generate models for all existing tables
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.10
|
|
@@ -3,13 +3,13 @@ class <%= class_name -%> < ActiveRecord::Base
|
|
|
3
3
|
<%= "set_primary_key #{primary_key.to_sym.inspect}" if primary_key %>
|
|
4
4
|
|
|
5
5
|
# Relationships
|
|
6
|
-
<%- relations[:has_some ].each do |table_name,
|
|
7
|
-
-%> has_many <%= LegacyData::TableClassNameMapper.class_name_for(table_name).underscore.pluralize.to_sym.inspect %>,
|
|
6
|
+
<%- relations[:has_some ].each do |table_name, options|
|
|
7
|
+
-%> has_many <%= LegacyData::TableClassNameMapper.class_name_for(table_name).underscore.pluralize.to_sym.inspect %><% options.each {|key, value| %>, <%="#{key.inspect} => #{value.inspect} "%> <%} %>
|
|
8
8
|
<%- end -%>
|
|
9
9
|
<%- relations[:belongs_to ].each do |table_name, foreign_key|
|
|
10
10
|
-%> belongs_to <%= LegacyData::TableClassNameMapper.class_name_for(table_name).underscore.to_sym.inspect %>, :foreign_key => <%= foreign_key.inspect %>
|
|
11
11
|
<%- end -%>
|
|
12
|
-
<%- relations[:has_and_belongs_to_many].each do |table_name,
|
|
12
|
+
<%- relations[:has_and_belongs_to_many].each do |table_name, opts|
|
|
13
13
|
-%> has_and_belongs_to_many <%= LegacyData::TableClassNameMapper.class_name_for(table_name).underscore.pluralize.to_sym.inspect %>, :foreign_key => <%= options[:foreign_key].inspect%>, :association_foreign_key => <%= options[:association_foreign_key].inspect%>, :join_table => <%= options[:join_table].inspect %>
|
|
14
14
|
<%- end -%>
|
|
15
15
|
|
data/legacy_data.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{legacy_data}
|
|
8
|
-
s.version = "0.0.
|
|
8
|
+
s.version = "0.0.10"
|
|
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-09-
|
|
12
|
+
s.date = %q{2009-09-24}
|
|
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 = [
|
|
@@ -20,7 +20,7 @@ module OracleEnhancedAdapterConstraintsMethods
|
|
|
20
20
|
|
|
21
21
|
# RSI: changed select from all_constraints to user_constraints - much faster in large data dictionaries
|
|
22
22
|
fks = select_rows(<<-SQL, 'Remote Foriegn Keys')
|
|
23
|
-
select c.table_name, cc.column_name
|
|
23
|
+
select c.table_name, cc.column_name, c.delete_rule
|
|
24
24
|
from user_constraints c, user_constraints parent_c, user_cons_columns cc
|
|
25
25
|
where c.owner = '#{owner}'
|
|
26
26
|
and parent_c.table_name = '#{table_name}'
|
|
@@ -29,6 +29,17 @@ module OracleEnhancedAdapterConstraintsMethods
|
|
|
29
29
|
and cc.owner = c.owner
|
|
30
30
|
and cc.constraint_name = c.constraint_name
|
|
31
31
|
SQL
|
|
32
|
+
fks.map do |row|
|
|
33
|
+
dependent = case row[3]
|
|
34
|
+
when 'CASCADE'
|
|
35
|
+
:destroy
|
|
36
|
+
when 'SET NULL'
|
|
37
|
+
:nullify
|
|
38
|
+
end
|
|
39
|
+
options = {:to_table => row[0].downcase, :foreign_key =>row[1].downcase.to_sym }
|
|
40
|
+
options[:dependent] = dependent unless dependent.nil?
|
|
41
|
+
options
|
|
42
|
+
end
|
|
32
43
|
end
|
|
33
44
|
|
|
34
45
|
def constraints(table_name)
|
data/lib/legacy_data/schema.rb
CHANGED
|
@@ -105,7 +105,7 @@ module LegacyData
|
|
|
105
105
|
|
|
106
106
|
has_some = {}
|
|
107
107
|
connection.foreign_keys_of(table_name).each do |relation|
|
|
108
|
-
has_some[relation.
|
|
108
|
+
has_some[relation.delete(:to_table).downcase] = relation
|
|
109
109
|
end
|
|
110
110
|
has_some
|
|
111
111
|
end
|
|
@@ -34,7 +34,7 @@ module LegacyData
|
|
|
34
34
|
other_table_name = join_table.belongs_to_tables.detect {|table_name| table_name != self.table_name}
|
|
35
35
|
relations[:has_and_belongs_to_many][other_table_name] = { :foreign_key =>join_table.belongs_to_relations[table_name],
|
|
36
36
|
:association_foreign_key=>join_table.belongs_to_relations[other_table_name],
|
|
37
|
-
:join_table =>join_table.table_name }
|
|
37
|
+
:join_table =>join_table.table_name.to_sym }
|
|
38
38
|
relations[:has_some].delete(join_table.table_name)
|
|
39
39
|
end
|
|
40
40
|
end
|
|
@@ -91,8 +91,10 @@ describe LegacyData::Schema do
|
|
|
91
91
|
|
|
92
92
|
it 'should get all "has_some" (has_many and has_one) relationships when my primary key is the foreign key in another table ' do
|
|
93
93
|
@connection.should_receive(:respond_to?).with(:foreign_keys_of).and_return(true)
|
|
94
|
-
@connection.should_receive(:foreign_keys_of).and_return([
|
|
95
|
-
|
|
94
|
+
@connection.should_receive(:foreign_keys_of).and_return([ {:to_table=>'other_table', :foreign_key=>:pk, :dependent=>:destroy},
|
|
95
|
+
{:to_table=>'the_table', :foreign_key=>:pk, :dependent=>:destroy} ])
|
|
96
|
+
@schema.has_some_relations.should == {'other_table' => {:foreign_key=>:pk, :dependent=>:destroy},
|
|
97
|
+
'the_table' => {:foreign_key=>:pk, :dependent=>:destroy}}
|
|
96
98
|
end
|
|
97
99
|
|
|
98
100
|
it 'should give no "belongs_to" when the adapter does not support foreign keys' do
|
|
@@ -59,7 +59,7 @@ describe LegacyData::TableDefinition do
|
|
|
59
59
|
@posts.convert_has_many_to_habtm(@tag_posts)
|
|
60
60
|
|
|
61
61
|
@posts.relations[:has_some ].should == {}
|
|
62
|
-
@posts.relations[:has_and_belongs_to_many].should == {'tags' => {:foreign_key=>:posts_id, :association_foreign_key=>:tags_id, :join_table
|
|
62
|
+
@posts.relations[:has_and_belongs_to_many].should == {'tags' => {:foreign_key=>:posts_id, :association_foreign_key=>:tags_id, :join_table=>:tag_posts} }
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: alexrothenberg-legacy_data
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alex Rothenberg
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-09-
|
|
12
|
+
date: 2009-09-24 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|