Resetting sequences in unit tests with pg

Hi all,

Rails 1.0
Postgresql 8.1
Ruby 1.8.4

Is there a way to reset sequences in unit tests when loading fixture
data? I
came across mention of a "Fixtures.reset_sequences method here:

http://api.rubyonrails.com/files/vendor/rails/activerecord/CHANGELOG.html

However, when I tried to call Fixtures.reset_sequences in the setup
method, I
got a NoMethodError.

Any ideas?

Thanks,

Dan

Daniel B. wrote:

However, when I tried to call Fixtures.reset_sequences in the setup
method, I got a NoMethodError.

Any ideas?

Thanks,

Dan

A little further research indicates that the self.create_fixtures method
in
fixtures.rb does this:

if connection.respond_to?(:reset_pk_sequence!)
table_names.each do |table_name|
connection.reset_pk_sequence!(table_name)
end
end

However, reset_pk_seqence! in the postgresql adapter has this comment:

Resets sequence to the max value of the table’s pk if present.

So…if I want to reset the pk to the min, I’ll have to do that
manually.

Any reason this isn’t set to the minimum in the first place? Just
curious.

Regards,

Dan

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Jan 25, 2006, at 9:24 AM, Daniel B. wrote:

However, reset_pk_seqence! in the postgresql adapter has this comment:

Resets sequence to the max value of the table’s pk if present.

So…if I want to reset the pk to the min, I’ll have to do that
manually.

Any reason this isn’t set to the minimum in the first place? Just
curious.

To account for fixtures inserted without incrementing the sequence
(since
the fixture may specify a primary key.)

jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFD17glAQHALep9HFYRAuWKAJsFrz6xd6ST7jN5KGItM6JBwLTD0gCfVYpW
bY744RktgL5Wb2iL3qk1GF4=
=DNo1
-----END PGP SIGNATURE-----

Jeremy K. wrote:

manually.

Any reason this isn’t set to the minimum in the first place? Just
curious.

To account for fixtures inserted without incrementing the sequence (since
the fixture may specify a primary key.)

jeremy

Ah, thanks Jeremy. Makes sense.

Dan