code42 / pg_sequencer

Create and dump postgres sequences in your Rails app!
http://www.code42.com/
MIT License
17 stars 36 forks source link

Adds duplicate sequences to schema.rb #1

Closed mxey closed 6 years ago

mxey commented 12 years ago

When using pg_sequencer, the primary key sequences are also added to schema.rb, but they are automatically created as part of create_table. Running rake:db:setup fails because Rails tries to create sequences foo_id_seq that already exist.

tonyc commented 12 years ago

Hi Max,

Any thought on what the proper behavior should be?

Our usecase was that we were always manually creating the sequences and PK fields for tables, not relying on a column actually listed as PRIMARY KEY (don't ask :)).

I'm wondering if there's any way we can tell whether a sequence is a PK sequence, and if so, skip it so we don't conflict with create_table. I haven't looked at the code in a while, but I think we just query for all sequences.

On Sat, Sep 15, 2012 at 6:58 PM, Maximilian Gaß notifications@github.comwrote:

When using pg_sequencer, the primary key sequences are also added to schema.rb, but they are automatically created as part of create_table. Running rake:db:setup fails because Rails tries to create sequences foo_id_seq that already exist.

— Reply to this email directly or view it on GitHubhttps://github.com/code42/pg_sequencer/issues/1.

mxey commented 12 years ago

Can you give me your schema.rb as an example? I would like to compare it to mine to see how your tables look in that definition.

tonyc commented 12 years ago

Now that I think of it, we never actually used the schema dumper feature. We ended up using SQL schema dumps, so the ruby version of schema.rb is essentially untested, like a boss :)

Would it be easy for you to pastebin a sample schema.rb? I'm not actively involved with the project that used pg_sequencer anymore, but maybe this is a good excuse to get back involved.

On Sat, Sep 29, 2012 at 4:50 PM, Maximilian Gaß notifications@github.comwrote:

Can you give me your schema.rb as an example? I would like to compare it to mine to see how your tables look in that definition.

— Reply to this email directly or view it on GitHubhttps://github.com/code42/pg_sequencer/issues/1#issuecomment-9008635.

mxey commented 12 years ago

I gisted both the dumped schema.rb and the one where I stripped out duplicate sequences: https://gist.github.com/3829365

tonyc commented 12 years ago

OK. So it does boil down to not simply writing out all of the sequences to schema.rb. Assume that sequences will be generated for calls to create_table, which means filtering out sequences that belong to the PK of a table.

Does that sound right?

On Wed, Oct 3, 2012 at 2:46 PM, Maximilian Gaß notifications@github.comwrote:

I gisted both the dumped schema.rb and the one where I stripped out duplicate sequences: https://gist.github.com/3829365

— Reply to this email directly or view it on GitHubhttps://github.com/code42/pg_sequencer/issues/1#issuecomment-9119524.

mxey commented 12 years ago

On 03.10.2012, at 22:54, Tony Collen notifications@github.com wrote:

OK. So it does boil down to not simply writing out all of the sequences to schema.rb. Assume that sequences will be generated for calls to create_table, which means filtering out sequences that belong to the PK of a table.

Does that sound right?

Yes.

achempion commented 7 years ago

I wrote a quick fix to solve problem. Read rails section for explanation - https://github.com/achempion/pg_sequencer

benlinton commented 7 years ago

Here's a robust solution: https://github.com/code42/pg_sequencer/pull/11

This approach dumps all sequences to the schema.rb unless they're owned by any table's primary key.

amoravec commented 6 years ago

Thank you for your feedback, unfortunately this project was effectively abandoned and will no longer be maintained by Code42.