July 28th, 2009 — emacs, programming, ruby, snippets
I have just updated my Shoulda snippets for the Emacs YASnippets templating package. Shoulda is a ruby-based testing framework that consists of test macros, assertions, and helpers added on to the Test::Unit ruby framework. The snippets are based, and in many cases copied from the TextMate Shoulda snippet bundle, and modified where needed to work with the YASnippets package. New features in the recently released 0.6beta of YASnippet allow support for more of the TextMate-based snippets. The new YASnippet functionality is discussed in more detail in a post I did on Emacs Blog.
In order to port many of the snippets over from the TextMate bundle I wrote a script that automates the process. There is a Python script that does something very similar. The writing of my script was more of just a code kata for me, so take a look at both. One may be more suitable for your needs.
February 23rd, 2009 — oracle, plugins, programming, ruby
If you have tried
in a rails app when using Oracle as your database, then you have probably been slightly disappointed. The same rake task for MySQL and Postgres dumps everything you need to recreate the database. The task for Oracle only dumps SQL for the table creation (no constraints), and for the sequences. The active_record_oracle_extensions plug now supports dumping sql for the following:
- primary keys
- indexes
- foreign keys
- synonyms
I have added enough functionality to scratch my itch. If you need something else or find a bug let me know.
January 2nd, 2009 — oracle, plugins, programming, ruby
The active_record_oracle_extensions plugin provides support for adding foreign keys to migrations, adding synonyms to migrations, and disabling foreign key constraints during fixture loading. These are features that I needed in my applications, but either did not exist in other plugins, or the plugins seem to have been abandoned.
Installing into a Rails app
$ script/plugin install git://github.com/eyestreet/active_record_oracle_extensions.git
Adding Foreign Keys In a Migration
The example below shows a snippet from a migration that adds a foreign key.
def self.up
create_table :assets, :force => true do |t|
t.integer :media_record_id
t.string :media_file_name
t.string :media_content_type
t.integer :media_file_size
t.datetime :media_updated_at
t.timestamps
end
add_foreign_key_constraint :assets, :media_record_id,
:media_records, :id
end
Adding a Synonym in Migration
The example below shows the creation of a synonym named events for other_user.events. The force option adds “or replace” to the sql that generates the synonym. It is assumed that the user under which your are creating the synonym already has the needed grants to allow the creation of the synonym on other_user.
add_synonym :events, :other_user, :events, :force => true
Disabling Constraints During Fixture Loading
If you are using sys or system as your user for your rails application, then do not use this plugin, or use it at your own risk. During fixture loading, this plugin disables constraints for the user that has established the connection to oracle, and then re-enables the constraints after the load.