Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fixes for Rails 2 / Foreign Keys / Empty fixture directories #6

Merged
merged 1 commit into from over 2 years ago

2 participants

Jeff Dean Ryan Dy
Jeff Dean
zilkey commented May 15, 2011

These changes allow Rails 2 users, users with foreign key constraints and users with empty fixture directories to use FixtureBuilder.

Ryan Dy
Owner

is it possible to apply the fix to master branch as it stands? since you are more familiar with the change it might be easier for you to perform the merge at your end first. there has been a pretty big refectoring done so I'm not sure how cleanly this patch will merge.

Jeff Dean

Here's the only piece that doesn't seem like it was covered from your recent commits. I tried testing it, but SQLite doesn't have true foreign key constraints, so I couldn't actually get a failing test. I could have just asserted that the disable_referential_integrity method was called, but that seemed dumb.

For the record, the referential integrity change is to make it so that you can delete tables that have foreign keys and data is still referenced by child tables (which happens when there is existing data left in the db after a test run).

CREATE TABLE magical_creatures(
  id serial
);

CREATE TABLE unicorns(
  magical_creature_id INTEGER,
  FOREIGN KEY(magical_creature_id) REFERENCES magical_creatures(id)
);

insert into magical_creatures(id) values (1);

insert into unicorns(magical_creature_id) values (1);

drop table magical_creatures; --<< this should raise an error (and does in postgres) but does not

If you need a test in order to apply the patch, I'll have to add a dependency on postgres for the test suite. Let me know what you'd like to do.

Ryan Dy
Owner

this seems fine to me, as long as it works in a repository somewhere with this portion of code, its probably to ok to skip the postgres dependency.

i'll merge it now then push a new version, if you could let me know if the github version works fine with a test repo i'll release a new gem.

Ryan Dy rdy merged commit 2d96ffd into from September 19, 2011
Ryan Dy rdy closed this September 19, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Sep 18, 2011
Jeff Dean disable referential integrity when deleting tables so databases with …
…contraints don't fail
9e03894
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 3 additions and 1 deletion. Show diff stats Hide diff stats

  1. 4  lib/fixture_builder/builder.rb
4  lib/fixture_builder/builder.rb
@@ -54,7 +54,9 @@ def clean_out_old_data
54 54
     end
55 55
 
56 56
     def delete_tables
57  
-      tables.each { |t| ActiveRecord::Base.connection.delete(delete_sql % ActiveRecord::Base.connection.quote_table_name(t)) }
  57
+      ActiveRecord::Base.connection.disable_referential_integrity do
  58
+        tables.each { |t| ActiveRecord::Base.connection.delete(delete_sql % ActiveRecord::Base.connection.quote_table_name(t)) }
  59
+      end
58 60
     end
59 61
 
60 62
     def delete_yml_files
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.