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

Ticket #2292 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

[PATCH] add sequence_name support for postgresql

Reported by: rick Assigned to: Jeremy Kemper <rails@bitsweat.net>
Priority: normal Milestone: 1.0
Component: ActiveRecord Version: 0.13.1
Severity: normal Keywords: postgresql sequence
Cc: technoweenie@gmail.com, robby@planetargon.com

Description

It's already there for Oracle, and I needed it for postgres, so i created a default_sequence_format method in the respective adapters.

Attachments

sequence_fix.2322.diff (6.0 kB) - added by rick on 09/24/05 20:47:26.
sequence_fix_with_fixture_fix.2322.diff (10.0 kB) - added by rick on 09/24/05 20:53:42.
merged with previous fixture patch
squence_fix_with_fixture_fix.2339.diff (10.8 kB) - added by rick on 09/25/05 19:31:45.
Updated for rev 2339. as a bonus, includes a call to reset_sequences in the belongs_to test since orders has no fixture.
pg_seq.2352.diff (11.3 kB) - added by rick on 09/26/05 22:43:47.
merged w/ #962 and #2016
pg_seq.2363.diff (13.0 kB) - added by Rick on 09/27/05 11:33:03.
get some coalesce() action up in here

Change History

09/24/05 20:47:26 changed by rick

  • attachment sequence_fix.2322.diff added.

09/24/05 20:53:42 changed by rick

  • attachment sequence_fix_with_fixture_fix.2322.diff added.

merged with previous fixture patch

09/24/05 20:54:56 changed by rick

  • cc set to technoweenie@gmail.com.

Added a new version of the patch that is merged with the changes from #2224. This may also be a solution for #2016...

09/25/05 19:31:45 changed by rick

  • attachment squence_fix_with_fixture_fix.2339.diff added.

Updated for rev 2339. as a bonus, includes a call to reset_sequences in the belongs_to test since orders has no fixture.

09/26/05 13:45:19 changed by blair

Hello,

In this section of the patch, the documentation is incorrect for PostgreSQL.

       # Setting the sequence name when using other dbs will have no effect.
-      # If a sequence name is not explicitly set when using Oracle, it will
-      # default to the commonly used pattern of: #{table_name}_seq
+      # If a sequence name is not explicitly set, it will default to the 
+      # commonly used pattern of: #{table_name}_seq for Oracle and #{table_name}_id_seq
+      # for PostgreSQL.

It should probably read

+      # commonly used pattern of: #{table_name}_seq for Oracle and
+      # #{table_name}_#{pk}_seq for PostgreSQL.

Regards, Blair

09/26/05 20:49:12 changed by bitsweat

  • cc changed from technoweenie@gmail.com to technoweenie@gmail.com, robby@planetargon.com.
  • owner changed from David to Jeremy Kemper <rails@bitsweat.net>.

Rick, Robby -- could you guys merge #2016 and #962 with this patch (or vice versa)?

09/26/05 22:43:47 changed by rick

  • attachment pg_seq.2352.diff added.

merged w/ #962 and #2016

09/26/05 22:44:59 changed by rick

Merged. Also, moved reset_sequences and pgsql-specific code to the adapter so that create_fixtures will call that on any adapter with that method defined.

09/27/05 11:31:58 changed by rick

Okay, new version that incorporates the usage of COALESCE() in [2357]. I think the values were backwards, so it should be SELECT COALESCE(MAX(id)+1, 1) instead. I was getting mad breakage otherwise.

Also added a couple tests to adapter_test.rb to make sure tables with empty tables or tables with special pkeys are handled just like all the other tables.

09/27/05 11:33:03 changed by Rick

  • attachment pg_seq.2363.diff added.

get some coalesce() action up in here

10/06/05 14:02:51 changed by rick

I just wanted to add that if you're trying the new fixtures file and it's not working in your tests, try this in test_helper.rb:

require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'application'

require 'test/unit'
if File.directory?("#{RAILS_ROOT}/vendor/rails")
  require 'rails/activerecord/lib/active_record/fixtures'
  require 'rails/actionpack/lib/action_controller/test_process'
  require 'rails/actionwebservice/lib/action_web_service/test_invoke'
else
  require 'active_record/fixtures'
  require 'action_controller/test_process'
  require 'action_web_service/test_invoke'
end
require 'breakpoint'

It was loading everything from the latest gem (even though I had the vendor/rails directory) and driving me crazy.

10/16/05 04:35:51 changed by bitsweat

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

Sequence support merged; fixtures changes pending #1911. Changesets [2639], [2640], [2641].

06/17/06 11:03:34 changed by anonymous

  • version changed from 0.13.1 to 1.1.1.
  • type changed from defect to task.
  • severity changed from normal to critical.
  • milestone set to 1.2.

ghgh

06/17/06 19:07:27 changed by bitsweat

  • version changed from 1.1.1 to 0.13.1.
  • type changed from task to defect.
  • severity changed from critical to normal.
  • milestone changed from 1.2 to 1.0.