Existing Oracle schema with its own sequence

I’m mapping a new RoR application onto an existing Oracle schema. The
tables usually have a primary key named id, but the sequences that
assign new id values don’t have Rails-convention names. Is there a way
to tell Rails that the sequence for table FOO is not FOO_SEQ, but
XYZ_SEQ?

If that’s not possible, is there a way to create the equivalent of a
table’s view, but for a sequence?

Looking forward to any suggestions. Thanks.

I got an answer from Railsfrance: set_sequence_name(value = nil,
&block) can be used. I hadn’t been able to find the word “sequence” in
the index of the AWDwR2 book…

On Aug 13, 8:06 am, gers32 [email protected] wrote:

I got an answer from Railsfrance: set_sequence_name(value = nil,
&block) can be used. I hadn’t been able to find the word “sequence” in
the index of the AWDwR2 book…

i think you want to Google for “legacy app” or “legacy schema”
There’s quite a few blogs and threads here.

I have the same question (i.e., conflicts with oracle triggers and
rails). Also, I am finding that I have the following problem using
legacy sequences with non-rails names:

Even if I do set_sequence_name in the model, and even if I create the
proper sequences in my migrations, when I run rake test, rails wipes
out my test database and recreates it without the custom sequences
(though they exist in the development db), so I always get a “sequence
does not exist” in my create tests.

Is there some way to use the test_helper to hook into the test case
scenarios and fix this before the tests run?

Here’s my solution: weeblog: Non-Standard
Sequences and Rails Tests

Yes, I did search the site for these keywords and other combinations.
I couldn’t find an answer to my follow-up question:

The legacy Oracle schema uses triggers to get the sequences’ next
values. Isn’t there a potential conflict with Rails’ mechanism during
record creation?

If so, should I tell Rails to use the existing trigger mechanism (and
how), or should I deactivate the triggers exclusively for my
application - the tables are being accessed by other legacy apps -
(and how)?

Last thought : I’m going to create views, so that I can use the Rails
naming conventions. Maybe that solves my problem, assuming I can link
the sequence to the view?

You can tell I’m new both to RoR and Oracle, can’t you…

Thanks, Chris.

Le mécanisme d’affectation des clés primaires n’est pas clair, dans le
contexte de ma base existante : celle-ci utilise des “triggers” pour
récupérer la nouvelle valeur dans la séquence. Comment éviter un
conflit entre ceux-ci et Rails, lors de la création d’un nouvel
enregistrement ? Dois-je dire à Rails d’utiliser le mécanisme existant
(via “triggers”) et comment ? Ou alors, dois-je inactiver les
“triggers” pour mon application (sachant que d’autres applis ont
accèsà la même base) et comment ?

RoR et Oracle sont nouveaux pour moi ; ça se voit, non ?

Here’s the solution I came up with (for the testing issue):

http://weenet.blogspot.com/2007/09/non-standard-sequences-and-rails-tests.html#links