Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #1798 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

[PATCH] omnibus Oracle patch, fixes issues with sequences, camelCase, tests, and synonyms

Reported by: mschoen Assigned to: David
Priority: normal Milestone: 0.9.5
Component: ActiveRecord Version: 0.13.1
Severity: blocker Keywords: oci, camelcase, sequence, oracle
Cc: david@loudthinking.com

Description

This patch combines 4 previous patches:

#1751: [PATCH] Named sequences for oracle
#1784: [PATCH] Support use of synonyms in Oracle
#1787: [PATCH] Change Oracle sequences to #{table_name}_seq
#1793: [PATCH] Fix OCI camelCase and base_test unit tests

In particular, #1751 and #1787 have been integrated using the following approach:

1. change the default sequence name from rails_sequence to #{table_name}_seq to better handle automagically most folks using Oracle (as per my patch)

2. add the set_sequence_name method (as per Caleb's patch) to allow folks to override. if anyone really wanted to keep the current default, they could AR::B.set_sequence_name, and have it inherited. or use the block approach to do anything else fancy (as per John's idea)

Rails Oracle support will be in better shape if this patch can be applied before the 1.0 release -- it implements the commonly used standard for sequences in Oracle, along with making rake test_oci pass all tests.

Attachments

oci_omnibus.patch (19.3 kB) - added by mschoen on 07/21/05 18:03:07.
Patch file (from svn diff)
oci_omnibus.2.patch (18.7 kB) - added by anonymous on 07/23/05 12:54:49.
Now includes the code from ticket 1807
oci_omnibus.3.patch (24.2 kB) - added by mschoen on 07/24/05 03:16:23.
Patch file
oci_omnibus.changelog (1.3 kB) - added by mschoen on 07/24/05 03:16:51.
Proposed changelog

Change History

07/21/05 18:03:07 changed by mschoen

  • attachment oci_omnibus.patch added.

Patch file (from svn diff)

07/21/05 18:16:20 changed by crutan@gmail.com

  • summary changed from omnibus Oracle patch, fixes issues with sequences, camelCase, tests, and synonyms to [PATCH] omnibus Oracle patch, fixes issues with sequences, camelCase, tests, and synonyms.

07/22/05 06:53:48 changed by david

Won't "change the default sequence name from rails_sequence to #{table_name}_seq" break backwards compatibility? (We can't really do that)

07/22/05 08:31:33 changed by sam.mayes@gmail.com

It will break it, but this is how it should be in AR for oracle. If you go into any oracle shop and tell them they need to do it with rails sequence, you wont be using rails. The only options I see are

1. dont change (bad) 2. Implement patch as is existing apps can use set_sequence_name and itll be fine 3. make the default sequence name changeable so you could set the default to rails_sequence or tablename_seq ??

07/22/05 10:51:57 changed by crutan@gmail.com

Yeah, I'd have to agree with Sam here. We're pretty much an oracle-only shop, and having one global sequence is what prompted me to write my portion of this patch. We just can't use rails with a global sequence.

And with AR::Base.set_sequence_name it can be overridden to go back to rails_sequence if need be. It is just a matter of setting that up in the models. This really is a 1.0 feature for those of us that are using oracle. Especially for any sort of existing database support. I know that is not necessarily the biggest priority for Rails, but it does make it nice.

Plus, there's going to have to be some pain, at some point, for people using oracle. Either everyone who does things the oracle way, creating sequences and all that, will be defining every sequence name in every table, or this change gets made, and the set of folks who are using rails_sequence makes the change now. From my perspective, I think it makes sense to play nice with the way most oracle folks are used to working, cause a little pain now for OCI/rails_sequence users, but gain much broader appeal in the long run.

If, in the short term, you on the development team feel strongly about backwards compatibility, then perhaps you could accept part of this one, patch 1751, which at least allows the setting of the sequence name? That would let me, and others who use oracle's features, use rails with oracle.

caleb

07/22/05 12:31:09 changed by mschoen

Clearly I agree with Caleb and Sam (since I submitted the patch). We're on the Rails train regardless, but I'd like to see Rails fit better into a typical Oracle environment as of the 1.0 release.

The upgrade path to retain compatibility is also really easy. Either:

a. I expect most folks using Oracle ALREADY have sequences named #{table_name}_seq, so they'll just breathe a sigh of relief and drop the rails_sequences they had previously been forced to use.

b. If they prefer the rails_sequence, all they need to do is add, to the end of environment.rb:

ActiveRecord::Base.set_sequence_name = "rails_sequence"

Is absolute compatibility with previous releases without any changes (even the single line in option b above) by the developer is a requirement? I didn't think it was until POST 1.0, which is why I'm hoping to get this patch accepted prior to that milestone.

07/22/05 17:49:06 changed by defiler@null.net

In my opinion, Oracle is not a functional Rails adapter without this patch. I have a number of tables that need sequences, and they all use 'id' as their primary key name. Unless I'm missing some big piece of documentation somewhere, the existing oci adapter does not allow this. Sequences are global, not table-specific.. You can only have one sequence called 'rails_sequence' If it were up to me, I would mark this as a 'blocker' for Rails 1.0

07/22/05 19:03:15 changed by david

That's the kind of feedback I was hoping for :). Okay, I'll trust your judgement here and send anyone screaming your way. Thanks for spending the time to make Rails great on Oracle.

07/23/05 00:47:19 changed by nzkoz

Alternatively you could use:

  ActiveRecord::Base.set_sequence_suffix="seq"

Full backwards compatibility if you do it that way. Having said that, I don't believe there are too many rails applications in use at present, so perhaps a little breakage isn't so bad.

Is there any reason not to do a set_suffix?

07/23/05 02:09:04 changed by mschoen

If full backwards compatibility were required, I'd prefer the approach of having the patch as is, except have the sequence name default to "rails_sequence", and then achieve the desired effect with:

ActiveRecord::Base.set_sequence_name = "#{table_name}_seq"

This would retain the full flexibility of allow non-standard sequence names (whereas the suffix approach would be more limited).

However, I feel strongly that Rails will be better positioned for success in Oracle environments if the default is consistent with how most Oracle shops operate. Ie., I think that compatibility with the potential base of Rails/Oracle folks is more important at this point that with the current base of Rails/Oracle shops.

And perhaps more important, DHH seems to agree. ;-)

07/23/05 04:34:23 changed by nzkoz

Ok, My objections are registered, but remember, david's going to send the complainers your way ;).

07/23/05 06:18:51 changed by david

Perhaps you guys could verify and judge a few more members for the omnibus? Please have a look at #1807, #1604 (and extending it to include all the Rakefile tasks), and #714. Thanks, guys.

07/23/05 06:19:04 changed by david

  • cc set to david@loudthinking.com.

07/23/05 12:54:49 changed by anonymous

  • attachment oci_omnibus.2.patch added.

Now includes the code from ticket 1807

07/23/05 12:56:59 changed by crutan@gmail.com

Per David's suggestion, I've added in the code from ticket 1807 to this patch. I've got a super-busy weekend here, but I will snag the code from the 714 as well and take a look at it, though if anyone else thinks they can get it done before monday, please feel free to take a crack at it, as I can't make any guarantees of free time today or tomorrow!

caleb

07/24/05 03:14:12 changed by mschoen

I've attached version 3 of the omnibus patch, which closes #1624 and #714, along with notes for the changelog.

With David's gentle prodding, I think we've helped make Oracle a full-fledged citizen in the Rails workd.

07/24/05 03:16:23 changed by mschoen

  • attachment oci_omnibus.3.patch added.

Patch file

07/24/05 03:16:51 changed by mschoen

  • attachment oci_omnibus.changelog added.

Proposed changelog

07/24/05 14:02:06 changed by david

  • status changed from new to closed.
  • resolution set to fixed.

I've applied the patch with a few stylistic changes. Please rerun the tests and make sure everything still works.

07/24/05 18:17:27 changed by mschoen

Checked out the trunk again -- couldn't find the stylistic changes, but everything still seems to work. Thanks!

10/13/05 14:11:01 changed by loriolson@mac.com

  • severity changed from normal to blocker.

I am concerned that a portion of the patch from 1784 was lost in translation. Specifically, the part where the reference to user_tab_columns was replaced by a more complicated (but correct) reference to all_tab_columns. I know from using the current OCI adapter (0.13.1), that it is STILL referencing user_tab_columns

Here is the relevent patch code I found from 1784:

Index: activerecord/lib/active_record/connection_adapters/oci_adapter.rb
===================================================================
--- activerecord/lib/active_record/connection_adapters/oci_adapter.rb	(revision 1860)
+++ activerecord/lib/active_record/connection_adapters/oci_adapter.rb	(working copy)
@@ -155,7 +155,11 @@
         def columns(table_name, name = nil)
           cols = select_all(%Q{
               select column_name, data_type, data_default, data_length, data_scale
-              from user_tab_columns where table_name = '#{table_name.upcase}'}
+              from user_catalog cat, user_synonyms syn, all_tab_columns col
+              where cat.table_name = '#{table_name.upcase}'
+              and syn.synonym_name (+)= cat.table_name
+              and col.owner = nvl(syn.table_owner, user)
+              and col.table_name = nvl(syn.table_name, cat.table_name)}
           ).map { |row|
             OCIColumn.new row['column_name'].downcase, row['data_default'],
               row['data_length'], row['data_type'], row['data_scale']

10/13/05 18:13:58 changed by mschoen

The patch was applied, but AFTER 0.13.1 -- you can use the patched version by either running on edge rails, or by using the latest beta gems.

The next official release (expected soon) will include the patch as well.

05/28/06 16:43:49 changed by kkkkoaaa

  • milestone set to 0.9.5.

Keep a good job up! http://quick-adult-links.com

06/12/06 02:33:22 changed by anonymous

  • type set to defect.

tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet tatunet