Hi all,
> they are inserted into the table. I'm wondering if the triggers that
> populate the change table are being called out of sequence somehow.
Having thought a little more about this, I have a theory as to how FK
constraints can be violated during replication.
As far as I can tell RubyRep uses the triggers to record which table
rows have changed and when replicating the changes to the other
database uses the resulting rr_pending_changes to tell it what rows to
insert/update. Is it possible for a row to be inserted then changed
in one db before the row has been replicated to the other? If so, is
it therefore possible that a row that has yet to be inserted in the
second db is updated in the first to now contain a value in a FK
column and that the attempt to insert that row in the second db will
fail due to a FK constraint on that column?
To explain, our company sells insurance online and we like to allow
our customers return to our site to revisit their quotations. We have
a 'quotes' table to hold the quote data and a 'users' table for our
cusomers' user accounts. Our 'quotes' table has a FK column 'user_id'
that references '
users.id' and their is a constraint on this column.
We first insert into the 'quotes' table at the beginning of the quote
process. At some point later in the process a 'user' account can be
created and inserted into 'users' and then associated with the quote
by updating quotes.user_id with the id of the user. So far so good.
However, if the time elapsed between the initial creation of the entry
in 'quotes', the insertion of a 'user' and the update of the quote row
is small, then it can all happen *before* rubyrep has replicated any
of it. Since rubyrep would process changes in order, you'd hope that
the replication would be smooth.
However, I think what's happening is that rubyrep sees that it needs
to insert a row into 'quotes', before inserting into 'users', but that
the columns it inserts will include the FK user_id in its final state
thus breaking the FK constraint, because it hasn't yet processed the
'users' row.
Does that make sense? If so, what can be done about it. We've moved
to Bucardo for now, but I'd like to be able to return to Rubyrep for
its ease of use and because our app is a Rails app.