automatic_foreign_key 1.0.1 → 1.0.2

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/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 1.0.2
2
+ * rails 3 generator
3
+ 1.0.1
4
+ * used autoload
5
+ * rails 3 compatibility
1
6
  1.0.0
2
7
  * renamed from foreign_key_migration to automatic_foreign_key
3
8
  * added gemspec
data/README.rdoc CHANGED
@@ -77,6 +77,14 @@ configuration properties:
77
77
  * <code>config.active_record.table_name_prefix</code>
78
78
  * <code>config.active_record.table_name_suffix</code>
79
79
 
80
+ === Rails 3 compatibility
81
+
82
+ Automatic foreign key is fully compatibly with Rails 3.
83
+
84
+ === Rails 2.x compatibility
85
+
86
+ Everything but generator is compatible
87
+
80
88
  === Dependencies
81
89
 
82
90
  * RedHill on Rails Core (redhillonrails_core).
data/Rakefile CHANGED
@@ -13,6 +13,7 @@ constraints when creating tables. It uses SQL-92 syntax and as such should be co
13
13
  gem.homepage = "http://github.com/mlomnicki/automatic_foreign_key"
14
14
  gem.authors = ["Michał Łomnicki"]
15
15
  gem.add_dependency "redhillonrails_core", ">= 1.0.2"
16
+ gem.add_dependency "activerecord", ">= 2.2"
16
17
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
18
  end
18
19
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{automatic_foreign_key}
8
- s.version = "1.0.1"
8
+ s.version = "1.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michał Łomnicki"]
12
- s.date = %q{2010-03-29}
12
+ s.date = %q{2010-03-30}
13
13
  s.description = %q{Automatic Key Migrations is a gem that automatically generates foreign-key
14
14
  constraints when creating tables. It uses SQL-92 syntax and as such should be compatible with most databases that support foreign-key constraints.}
15
15
  s.email = %q{michal.lomnicki@gmail.com}
@@ -25,14 +25,14 @@ constraints when creating tables. It uses SQL-92 syntax and as such should be co
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "automatic_foreign_key.gemspec",
28
- "generators/foreign_key_migration/foreign_key_migration_generator.rb",
29
- "generators/foreign_key_migration/templates/migration.rb",
30
28
  "init.rb",
31
29
  "install.rb",
32
30
  "lib/automatic_foreign_key.rb",
33
31
  "lib/automatic_foreign_key/active_record/base.rb",
34
32
  "lib/automatic_foreign_key/active_record/connection_adapters/table_definition.rb",
35
- "lib/automatic_foreign_key/active_record/migration.rb"
33
+ "lib/automatic_foreign_key/active_record/migration.rb",
34
+ "lib/generators/automatic_foreign_key/migration_generator.rb",
35
+ "lib/generators/automatic_foreign_key/templates/migration.rb"
36
36
  ]
37
37
  s.homepage = %q{http://github.com/mlomnicki/automatic_foreign_key}
38
38
  s.rdoc_options = ["--charset=UTF-8"]
@@ -46,11 +46,14 @@ constraints when creating tables. It uses SQL-92 syntax and as such should be co
46
46
 
47
47
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
48
  s.add_runtime_dependency(%q<redhillonrails_core>, [">= 1.0.2"])
49
+ s.add_runtime_dependency(%q<activerecord>, [">= 2.2"])
49
50
  else
50
51
  s.add_dependency(%q<redhillonrails_core>, [">= 1.0.2"])
52
+ s.add_dependency(%q<activerecord>, [">= 2.2"])
51
53
  end
52
54
  else
53
55
  s.add_dependency(%q<redhillonrails_core>, [">= 1.0.2"])
56
+ s.add_dependency(%q<activerecord>, [">= 2.2"])
54
57
  end
55
58
  end
56
59
 
data/init.rb CHANGED
@@ -1 +1 @@
1
- require 'automatic_foreign_key' unless defined?(RedHillConsulting::AutomaticForeignKey)
1
+ require 'automatic_foreign_key' unless defined?(AutomaticForeignKey)
data/install.rb CHANGED
@@ -1 +1 @@
1
- puts "WARNING: You also need to install redhillonrails_core" unless File.exists?(File.join(File.dirname(__FILE__), "..", "redhillonrails_core"))
1
+ puts "Note redhillonrails_core dependency is needed"
@@ -0,0 +1,36 @@
1
+ require 'generators/active_record'
2
+ require 'active_record'
3
+
4
+ module AutomaticForeignKey
5
+ class MigrationGenerator < ::ActiveRecord::Generators::Base
6
+ argument :name, :default => 'create_automatic_foreign_keys'
7
+
8
+ def self.source_root
9
+ File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
10
+ end
11
+
12
+ def create_migration_file
13
+ set_local_assigns!
14
+ migration_template 'migration.rb', "db/migrate/#{file_name}"
15
+ end
16
+
17
+ protected
18
+ attr_reader :foreign_keys
19
+
20
+ def set_local_assigns!
21
+ @foreign_keys = determine_foreign_keys
22
+ end
23
+
24
+ def determine_foreign_keys
25
+ returning [] do |foreign_keys|
26
+ connection = ::ActiveRecord::Base.connection
27
+ connection.tables.each do |table_name|
28
+ connection.columns(table_name).each do |column|
29
+ references = ::ActiveRecord::Base.references(table_name, column.name)
30
+ foreign_keys << ::RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.new(nil, table_name, column.name, references.first, references.last) if references
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,4 +1,4 @@
1
- class <%= migration_name %> < ActiveRecord::Migration
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
2
  def self.up
3
3
  <% foreign_keys.each do |foreign_key| -%>
4
4
  <%= foreign_key.to_dump %>
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 1
9
- version: 1.0.1
8
+ - 2
9
+ version: 1.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Micha\xC5\x82 \xC5\x81omnicki"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-29 00:00:00 +02:00
17
+ date: 2010-03-30 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -31,6 +31,19 @@ dependencies:
31
31
  version: 1.0.2
32
32
  type: :runtime
33
33
  version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: activerecord
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 2
43
+ - 2
44
+ version: "2.2"
45
+ type: :runtime
46
+ version_requirements: *id002
34
47
  description: |-
35
48
  Automatic Key Migrations is a gem that automatically generates foreign-key
36
49
  constraints when creating tables. It uses SQL-92 syntax and as such should be compatible with most databases that support foreign-key constraints.
@@ -50,14 +63,14 @@ files:
50
63
  - Rakefile
51
64
  - VERSION
52
65
  - automatic_foreign_key.gemspec
53
- - generators/foreign_key_migration/foreign_key_migration_generator.rb
54
- - generators/foreign_key_migration/templates/migration.rb
55
66
  - init.rb
56
67
  - install.rb
57
68
  - lib/automatic_foreign_key.rb
58
69
  - lib/automatic_foreign_key/active_record/base.rb
59
70
  - lib/automatic_foreign_key/active_record/connection_adapters/table_definition.rb
60
71
  - lib/automatic_foreign_key/active_record/migration.rb
72
+ - lib/generators/automatic_foreign_key/migration_generator.rb
73
+ - lib/generators/automatic_foreign_key/templates/migration.rb
61
74
  has_rdoc: true
62
75
  homepage: http://github.com/mlomnicki/automatic_foreign_key
63
76
  licenses: []
@@ -1,24 +0,0 @@
1
- class ForeignKeyMigrationGenerator < Rails::Generator::NamedBase
2
- def initialize(runtime_args, runtime_options = {})
3
- runtime_args << 'create_foreign_keys' if runtime_args.empty?
4
- super
5
- end
6
-
7
- def manifest
8
- foreign_keys = []
9
-
10
- connection = ActiveRecord::Base.connection
11
- connection.tables.each do |table_name|
12
- connection.columns(table_name).each do |column|
13
- references = ActiveRecord::Base.references(table_name, column.name)
14
- foreign_keys << RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.new(nil, table_name, column.name, references.first, references.last) if references
15
- end
16
- end
17
-
18
- record do |m|
19
- m.migration_template 'migration.rb', 'db/migrate', :assigns => {
20
- :migration_name => class_name, :foreign_keys => foreign_keys
21
- }, :migration_file_name => file_name
22
- end
23
- end
24
- end