Permalink
Browse files

Enforce foreign key in Posts

This uses the Foreigner gem; Activerecord doesn't seem to have native
support for foreign keys in migrations yet.
  • Loading branch information...
1 parent 0ce3b29 commit ed2813b733a636ffc6843f849b3931a8ba322e51 @mistydemeo committed Aug 14, 2012
Showing with 17 additions and 0 deletions.
  1. +16 −0 db/migrate/20120814031102_posts_add_foreign_key.rb
  2. +1 −0 preeventualist.gemspec
@@ -0,0 +1,16 @@
+require 'foreigner'
+Foreigner.load
+
+class PostsAddForeignKey < ActiveRecord::Migration
+ def up
+ change_table :posts do |t|
+ t.foreign_key :posters, dependent: :delete
+ end
+ end
+
+ def down
+ change_table :posts do |t|
+ t.remove_foreign_key :posters
+ end
+ end
+end
View
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "sinatra-activerecord"
s.add_runtime_dependency "activerecord"
s.add_runtime_dependency "sqlite3"
+ s.add_runtime_dependency "foreigner"
s.add_development_dependency "cucumber"
s.add_development_dependency "rspec"

0 comments on commit ed2813b

Please sign in to comment.