forked from azimux/foreign_key_migrations
Snapshot of the (no longer supported?) foreign_key_migrations plugin
License
devwout/foreign_key_migrations
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
master
Could not load branches
Nothing to show
Could not load tags
Nothing to show
{{ refName }}
default
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code
-
Clone
Use Git or checkout with SVN using the web URL.
Work fast with our official CLI. Learn more about the CLI.
- Open with GitHub Desktop
- Download ZIP
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
This branch is 1 commit ahead of azimux:master.
Latest commit
Git stats
Files
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
= 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.
About
Snapshot of the (no longer supported?) foreign_key_migrations plugin
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- Ruby 100.0%