Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Referential integrity after primary key collisions #42

Closed
johncant opened this Issue Jan 2, 2012 · 4 comments

Comments

Projects
None yet
2 participants

johncant commented Jan 2, 2012

Hi all, I've got a question about this gem:

Supposing I have these models in Rails:

class Foo < ActiveRecord::Base
  acts_as_archive ....
  has_one :bar, :dependent => :destroy
end

class Bar < ActiveRecord::Base
  acts_as_archive ...
  belongs_to :foo
end

Then I do:

Foo.find(6).destroy # It ends up in Foo::Archive with id 6 and Foo.find(6).bar ends up in Bar::Archive

Then, much later, someone creates another Foo and unluckily it has id 6 and deletes it:

Foo.find(6).destroy # Primary key collision

What happens to the referential integrity of the archive tables?

Collaborator

elmatou commented Jan 3, 2012

Sadly this library is not supported anymore.
But because I had to dig in the code, I can tell you there is no integrity check.
The gem assume that id are affected incrementaly (eg : with AUTO_INCREMENT in MySQL).

johncant commented Jan 3, 2012

Can we assume this for any database that rails has an adapter for? For instance Postgres?

Collaborator

elmatou commented Jan 4, 2012

I'm pretty sure we can assume it for SQL databases (including PostgreSQL), but I have no idea for non relational databases (anyhow this library has no adapter for them).

@johncant johncant closed this Jan 4, 2012

johncant commented Jan 4, 2012

Cheers elmatou! Now I know that I can use in my app a version of this gem+mover+also_migrate and that I hacked to work with PostgreSQL and Rails 3.1 reversible migrations. I've submitted all of my changes. The annoying thing, we realised only after modifying acts_as_archive that it was going to be easier (in our case) to write a simpler version of acts_as_paranoid, which took an afternoon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment