Permalink
Browse files

Komplettumbau

mit foreigner als dependency
  • Loading branch information...
1 parent 7e95925 commit 5c7609d8d9c51f9013ff13cc37c545265619487c @TeaMoe committed Mar 13, 2012
Showing with 146 additions and 1,048 deletions.
  1. +0 −109 CHANGELOG
  2. +4 −0 Gemfile
  3. +0 −91 README
  4. +1 −0 Rakefile
  5. +0 −5 about.yml
  6. +25 −0 foreign_key_migrations.gemspec
  7. +0 −24 generators/foreign_key_migration/foreign_key_migration_generator.rb
  8. +0 −10 generators/foreign_key_migration/templates/migration.rb
  9. +0 −2 init.rb
  10. +0 −1 install.rb
  11. +0 −60 lib/core/active_record/base.rb
  12. +0 −46 lib/core/active_record/connection_adapters/abstract_adapter.rb
  13. +0 −21 lib/core/active_record/connection_adapters/column.rb
  14. +0 −26 lib/core/active_record/connection_adapters/foreign_key_definition.rb
  15. +0 −11 lib/core/active_record/connection_adapters/index_definition.rb
  16. +0 −37 lib/core/active_record/connection_adapters/mysql4_adapter.rb
  17. +0 −40 lib/core/active_record/connection_adapters/mysql5_adapter.rb
  18. +0 −92 lib/core/active_record/connection_adapters/mysql_adapter.rb
  19. +0 −8 lib/core/active_record/connection_adapters/mysql_column.rb
  20. +0 −131 lib/core/active_record/connection_adapters/postgresql_adapter.rb
  21. +0 −23 lib/core/active_record/connection_adapters/schema_statements.rb
  22. +0 −109 lib/core/active_record/connection_adapters/sqlite3_adapter.rb
  23. +0 −27 lib/core/active_record/connection_adapters/table_definition.rb
  24. +0 −25 lib/core/active_record/schema.rb
  25. +0 −58 lib/core/active_record/schema_dumper.rb
  26. +16 −12 lib/core_lib.rb
  27. +25 −0 lib/foreign_key_migrations.rb
  28. +0 −22 lib/foreign_key_migrations/active_record/base.rb
  29. +0 −28 lib/foreign_key_migrations/active_record/connection_adapters/table_definition.rb
  30. +0 −15 lib/foreign_key_migrations/active_record/migration.rb
  31. +26 −0 lib/foreign_key_migrations/connection_adapters/schema_statements.rb
  32. +20 −0 lib/foreign_key_migrations/connection_adapters/table_definition.rb
  33. +15 −0 lib/foreign_key_migrations/migration.rb
  34. +11 −0 lib/foreign_key_migrations/railtie.rb
  35. +3 −0 lib/foreign_key_migrations/version.rb
  36. +0 −3 lib/foreign_key_migrations_lib.rb
  37. +0 −3 test/test_helper.rb
  38. +0 −9 test/unit/foreign_key_migrations/active_record/base_test.rb
View
@@ -1,109 +0,0 @@
-[REVISION 20080131]
-
-[FIXED] Stack-level too deep.
-
-[NEW] Generate foreign keys for databases that currently have none. Doesn't check to see if the foreign key already exists, nor does it drop the foreign keys yet.
-
-[REVISION 20071128]
-
-[FIXED] Workaround to ensure plugin is only ever loaded once.
-
-[REVISION 20070905]
-
-[FIXED] "some_column_name" referenced in foreign key constraint does not exist.
-
-[REVISION 20070904]
-
-[NEW] Support :references keyword when calling primary_key().
-
-[NEW] [#11995] the parameter :references needs the second argument referencing the field name.
-
-[REVISION 20070707]
-
-[NEW] Support acts_as_tree convention: if a column is named parent_id it will be treated as a circular reference to the table in which it is defined.
-
-[REVISION 20070703]
-
-[FIXED] Foreign-keys not created when using add_column.
-
-[REVISION 20070628]
-
-[FIXED] Stack level too deep in 'add_column_without_foreign_key_migrations' (Ronen Barzel).
-
-[REVISION 20070503]
-
-[NEW] Support for SQL92 [NOT] DEFERRABLE on foreign keys.
-
-[REVISION 20061202]
-
-[CHANGED] Use Rails 1.2 alias_method_chain.
-
-[CHANGED] Separate modules into individual files.
-
-[REVISION 20061013]
-
-[NEW] install.rb informs user of missing dependencies.
-
-[REVISION 20060909]
-
-[CHANGED] Replaced dependence on defunct Foreign Key Support and Schema Defining plugins with a single dependece on RedHill on Rails Core.
-
-[REVISION 20060831]
-
-[CHANGED] Separated out generic foreign-key functionality into new foreign key support plugin.
-
-[REVISION 20060629]
-
-[NEW] Added foreign_key method to table to allow t.foreign_key(columns, references_table_name, references_column_names, options).
-
-[NEW] Support foreign keys in add_column as we do for initial table columns.
-
-[NEW] Support :on_update and :on_delete as options--with values of :set_null, :cascade, or :restrict--for all foreign key creation mechanisms.
-
-[REVISION 20060627]
-
-[CHANGED] Reverted to overloaded column method with optional :references as the preferred mechanism with belongs_to a "nicety". This is really as a result of using it in a large-scale production application where belongs_to just didn't feel right in many cases and was semantically ambiguous.
-
-[REVISION 20060824]
-
-[CHANGED] Replaced method and column option :references with :belongs_to in keeping with the rails model keywords. The references variations are still available but have been deprecated and will be removed.
-
-[NEW] Added options :dependent => :nullify to SET NULL or :dependent => :delete_all | :destroy to CASCADE DELETE.
-
-[REVISION 20060812]
-
-[NEW] Added new table method references(table, options) which is essentially an alias for column(:table_id, :integer, options).
-
-[REVISION 20060803]
-
-[FIXED] The method proper_pluralized_table_name tries to call pluralize_table_name where it should call pluralized_table_name.
-
-[REVISION 20060623]
-
-[FIXED] Another try at a hack-around for a "feature" of pluralize that when called to pluralize a word that is already in the plural, acts as singularize.
-
-[REVISION 20060616]
-
-[FIXED] Hack-around for a "feature" of pluralize that when called to pluralize a word that is already in the plural, acts as singularize. Ie. "countries".pluralize becomes "country"!
-
-[REVISION 200606004]
-
-[CHANGED] This plugin now depends on Schema Defining!
-
-[REVISION 20060602]
-
-[CHANGED] Simplified static method overriding thanks to Ryan Tomayko.
-
-[REVISION 20060525]
-
-[CHANGED] Disabled foreign-key generation when executing a schema dump. This is a temporary measure until I get around to batching up the foreign keys at the end of the script.
-
-[REVISION 20060523]
-
-[NEW] Support :references => nil to prevent unwanted foreign-keys.
-
-[FIXED] Pluralization.
-
-[REVISION 20060522]
-
-[FIXED] Infinite recursion caused by bug in 1.8.4 method_alias on windows.
View
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in foreign_key_migrations.gemspec
+gemspec
View
@@ -1,91 +0,0 @@
-= Foreign Key Migrations
-
-Foreign Key Migrations is a plugin that automatically generates foreign-key
-constraints when creating tables. It uses SQL-92 syntax and as such should be
-compatible with most databases that support foreign-key constraints.
-
-In the simplest case, the plugin assumes that if you have a column named
-+customer_id+ that you want a foreign-key constraint generated that references
-the +id+ column in the +customers+ table:
-
- create_table :orders do |t|
- t.column :customer_id, :integer, :null => false
- ...
- end
-
-If you have multiple columns referencing a table or for whatever reason, your
-column name isn't the same as the referenced table name, you can use the
-<code>:references</code> option:
-
- create_table :orders do |t|
- t.column :ordered_by_id, :integer, :null => false, :references => :customers
- ...
- end
-
-If you have a column with a name ending in +_id+ for which you do not wish a
-foreign-key to be generated, you can use <code>:references => nil</code>:
-
- create_table :orders do |t|
- t.column :external_id, :integer, :null => false, :references => nil
- ...
- end
-
-Sometimes you may (for legacy reasons) need to reference a primary key column that is
-named something other than +id+. In this case you can specify the name of the column:
-
- create_table :orders do |t|
- t.column :ordered_by_pk, :integer, :null => false, :references => [:customers, :pk]
- ...
- end
-
-You also have the option of specifying what to do on delete/update using
-<code>:on_delete</code>/<code>:on_update</code>, respectively to one of:
-<code>:cascade</code>; <code>:restrict</code>; and <code>:set_null</code>:
-
- create_table :orders do |t|
- t.column :customer_id, :integer, :on_delete => :set_null, :on_update => :cascade
- ...
- end
-
-If your database supports it (for example PostgreSQL) you can also mark the constraint as deferrable:
-
- create_table :orders do |t|
- t.column :customer_id, :integer, :deferrable => true
- ...
- end
-
-By convention, if a column is named +parent_id+ it will be treated as a circular reference to
-the table in which it is defined.
-
-Sometimes you may (for legacy reasons) need to name your primary key column such that it
-would be misinterpreted as a foreign-key (say for example if you named the primary key
-+order_id+). In this case you can manually create the primary key as follows:
-
- create_table :orders, :id => false do |t|
- ...
- t.primary_key :order_id, :references => nil
- end
-
-There is also a generator for creating foreign keys on a database that currently has none:
-
- ruby script/generate foreign_key_migration
-
-The plugin fully supports and understands the following active-record
-configuration properties:
-
-* <code>config.active_record.pluralize_table_names</code>
-* <code>config.active_record.table_name_prefix</code>
-* <code>config.active_record.table_name_suffix</code>
-
-=== Dependencies
-
-* RedHill on Rails Core (redhillonrails_core).
-
-=== See Also
-
-* Foreign Key Associations (foreign_key_associations).
-
-=== License
-
-This plugin is copyright 2006 by RedHill Consulting, Pty. Ltd. and is released
-under the MIT license.
View
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
View
@@ -1,5 +0,0 @@
-author: simon@redhillconsulting.com.au
-summary: Automatically generates foreign-key constraints when creating tables.
-homepage: http://www.redhillonrails.org
-license: MIT
-rails_version: EDGE
@@ -0,0 +1,25 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "foreign_key_migrations/version"
+
+Gem::Specification.new do |s|
+ s.name = "foreign_key_migrations"
+ s.version = ForeignKeyMigrations::VERSION
+ s.authors = ["Timo Göllner"]
+ s.email = ["timo.goellner@googlemail.com"]
+ s.homepage = ""
+ s.summary = %q{TODO: Write a gem summary}
+ s.description = %q{TODO: Write a gem description}
+
+ s.rubyforge_project = "foreign_key_migrations"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ # specify any dependencies here; for example:
+ # s.add_development_dependency "rspec"
+ # s.add_runtime_dependency "rest-client"
+ s.add_dependency 'foreigner'
+end
@@ -1,24 +0,0 @@
-class ForeignKeyMigrationGenerator < Rails::Generator::NamedBase
- def initialize(runtime_args, runtime_options = {})
- runtime_args << 'create_foreign_keys' if runtime_args.empty?
- super
- end
-
- def manifest
- foreign_keys = []
-
- connection = ActiveRecord::Base.connection
- connection.tables.each do |table_name|
- connection.columns(table_name).each do |column|
- references = ActiveRecord::Base.references(table_name, column.name)
- foreign_keys << RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.new(nil, table_name, column.name, references.first, references.last) if references
- end
- end
-
- record do |m|
- m.migration_template 'migration.rb', 'db/migrate', :assigns => {
- :migration_name => class_name, :foreign_keys => foreign_keys
- }, :migration_file_name => file_name
- end
- end
-end
@@ -1,10 +0,0 @@
-class <%= migration_name %> < ActiveRecord::Migration
- def self.up
-<% foreign_keys.each do |foreign_key| -%>
- <%= foreign_key.to_dump %>
-<% end -%>
- end
-
- def self.down
- end
-end
View
@@ -1,2 +0,0 @@
-require 'core_lib' unless defined?(Core)
-require 'foreign_key_migrations_lib' unless defined?(ForeignKeyMigrations)
View
@@ -1 +0,0 @@
-puts "WARNING: You also need to install redhillonrails_core" unless File.exists?(File.join(File.dirname(__FILE__), "..", "redhillonrails_core"))
@@ -1,60 +0,0 @@
-module Core::ActiveRecord
- module Base
- def self.included(base)
- base.extend(ClassMethods)
- end
-
- module ClassMethods
- def self.extended(base)
- class << base
- alias_method_chain :columns, :redhillonrails_core
- alias_method_chain :abstract_class?, :redhillonrails_core
- alias_method_chain :reset_column_information, :redhillonrails_core
- end
- end
-
- def base_class?
- self == base_class
- end
-
- def abstract_class_with_redhillonrails_core?
- abstract_class_without_redhillonrails_core? || !(name =~ /^Abstract/).nil?
- end
-
- def columns_with_redhillonrails_core
- unless @columns
- columns_without_redhillonrails_core
- cols = columns_hash
- indexes.each do |index|
- column_name = index.columns.reverse.detect { |name| name !~ /_id$/ } || index.columns.last
- column = cols[column_name]
- column.case_sensitive = index.case_sensitive?
- column.unique_scope = index.columns.reject { |name| name == column_name } if index.unique
- end
- end
- @columns
- end
-
- def reset_column_information_with_redhillonrails_core
- reset_column_information_without_redhillonrails_core
- @indexes = @foreign_keys = nil
- end
-
- def pluralized_table_name(table_name)
- ActiveRecord::Base.pluralize_table_names ? table_name.to_s.pluralize : table_name
- end
-
- def indexes
- @indexes ||= connection.indexes(table_name, "#{name} Indexes")
- end
-
- def foreign_keys
- @foreign_keys ||= connection.foreign_keys(table_name, "#{name} Foreign Keys")
- end
-
- def reverse_foreign_keys
- connection.reverse_foreign_keys(table_name, "#{name} Reverse Foreign Keys")
- end
- end
- end
-end
@@ -1,46 +0,0 @@
-module Core::ActiveRecord::ConnectionAdapters
- module AbstractAdapter
- def self.included(base)
- base.module_eval do
- alias_method_chain :drop_table, :redhillonrails_core
- end
- end
-
- def create_view(view_name, definition)
- execute "CREATE VIEW #{view_name} AS #{definition}"
- end
-
- def drop_view(view_name)
- execute "DROP VIEW #{view_name}"
- end
-
- def views(name = nil)
- []
- end
-
- def view_definition(view_name, name = nil)
- end
-
- def foreign_keys(table_name, name = nil)
- []
- end
-
- def reverse_foreign_keys(table_name, name = nil)
- []
- end
-
- def add_foreign_key(table_name, column_names, references_table_name, references_column_names, options = {})
- foreign_key = ForeignKeyDefinition.new(options[:name], table_name, column_names, ActiveRecord::Migrator.proper_table_name(references_table_name), references_column_names, options[:on_update], options[:on_delete], options[:deferrable])
- execute "ALTER TABLE #{table_name} ADD #{foreign_key}"
- end
-
- def remove_foreign_key(table_name, foreign_key_name, options = {})
- execute "ALTER TABLE #{table_name} DROP CONSTRAINT #{foreign_key_name}"
- end
-
- def drop_table_with_redhillonrails_core(name, options = {})
- reverse_foreign_keys(name).each { |foreign_key| remove_foreign_key(foreign_key.table_name, foreign_key.name, options) }
- drop_table_without_redhillonrails_core(name, options)
- end
- end
-end
Oops, something went wrong.

0 comments on commit 5c7609d

Please sign in to comment.