Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
frolic-redhillonrails_core
Advanced tools
= RedHill on Rails Core
RedHill on Rails Core is a plugin that features to support other RedHill on Rails plugins. Those features include:
Schema.define()
is running.=== View Support
The plugin provides a mechanism for creating and dropping views as well as preserving views when performing a schema dump:
create_view :normal_customers, "SELECT * FROM customers WHERE status = 'normal'" drop_view :normal_customers
=== Foreign Key Support
The plugin provides two mechanisms for adding foreign keys as well as preserving foreign keys when performing a schema dump. (Using SQL-92 syntax and as such should be compatible with most databases that support foreign-key constraints.)
The first mechanism for creating foreign-keys allows you to add a foreign key when defining a table. For example:
create_table :orders do |t| ... t.foreign_key :customer_id, :customers, :id end
You also have the option of specifying what to do on delete/update using
:on_delete
/:on_update
, respectively to one of: :cascade
; :restrict
; and :set_null
:
create_table :orders do |t| ... t.foreign_key :customer_id, :customers, :id, :on_delete => :set_null, :on_update => :cascade end
The second method allows you to create arbitrary foreign-keys at any time:
add_foreign_key(:orders, :customer_id, :customers, :id, :on_delete => :set_null, :on_update => :cascade)
In either case, if your database supports deferred foreign keys (for example PostgreSQL) you can specify this as well:
t.foreign_key :customer_id, :customers, :id, :deferrable => true add_foreign_key(:orders, :customer_id, :customers, :id, :deferrable => true)
By default, the foreign key will be assigned a name by the underlying database. However, if this doesn't suit
your needs, you can override the default assignment using the :name
option:
add_foreign_key(:orders, :customer_id, :customers, :id, :on_delete => :set_null, :on_update => :cascade, :name => :orders_customer_id_foreign_key)
You can also query the foreign keys for a model yourself by calling foreign_keys()
:
Order.foreign_keys
Or for an arbitrary table by calling foreign_keys(table_name)
on a database adapter.
Either method returns an array of the following meta-data:
If you need to drop a foreign-key, use:
remove_foreign_key :orders, :orders_ordered_by_id_fkey
The plugin also ensures that all foreign keys are output when performing a
schema dump. This happens automatically when running rake migrate
or
rake db:schema:dump
. This has particular implications when running
unit tests that contain fixtures. To ensure the test data is correctly reset after
each test, you should list your fixtures in order of parent->child. For example:
fixtures :customers, :products, :orders, :order_lines
Rails will then set-up and tear-down the fixtures in the correct sequence.
Some databases (PostgreSQL and MySQL for example) allow you to set a comment for a table. You can do this for existing tables by using:
set_table_comment :orders, "All pending and processed orders"
or even at the time of creation:
create_table :orders, :comment => "All pending and processed orders" do |t| ... end
You can clear table comments using:
clear_table_comment :orders
There is also a rake tasks to show all database tables and their comments:
rake db:comments
The plugin fully supports and understands the following active-record configuration properties:
config.active_record.pluralize_table_names
config.active_record.table_name_prefix
config.active_record.table_name_suffix
=== Model Indexes
ActiveRecord::Base already provides a method on connection for obtaining the
indexes for a given table. This plugin now makes it possible to obtain the
indexes for a given model--ActiveRecord::Base
--class. For example:
Invoice.indexes
Would return all the indexes for the +invoices+ table.
=== Schema Defining
The plugin also adds a method--defining?()
--to
ActiveRecord::Schema
to indicate when define()
is running. This is necessary
as some migration plugins must change their behaviour accordingly.
=== Case-insensitive Indexes
For PostgreSQL, you can add an option :case_sensitive => false
to add_index
which will generate an expression index of the form:
LOWER(column_name)
This means finder queries of the form:
WHERE LOWER(column_name) = LOWER(?)
are able to use the indexes rather require, in the worst case, full-table scans.
Note also that this ties in well with Rails built-in support for case-insensitive searching:
validates_uniqueness_of :name, :case_sensitive => false
=== Testing
The plugin is heavily dependent on the database and rspec testing is provided to verify if database supports plugin features.
Rspec and rspec-rails plugins are neccessary:
script/plugin install git://github.com/dchelimsky/rspec.git script/plugin install git://github.com/dchelimsky/rspec-rails.git script/generate rspec
The plugin test use rails test database so it must be created before the tests are run:
rake db:create RAILS_ENV=test
And then run the plugin specs with:
rake specs:plugins
The plugin was tested on:
Currently only foreign key functionality is tested === See Also
=== License
This plugin is copyright 2006 by RedHill Consulting, Pty. Ltd. and is released under the MIT license.
FAQs
Unknown package
We found that frolic-redhillonrails_core demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.