Forum: Ruby on Rails db/schema.rb and PostgreSQL sequences

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Henning K. Pedersen (Guest)
on 2005-12-20 11:11
(Received via mailing list)

I'm working the "proper way" with creating the initial db schema via
migrations and db/schema.rb.

However, I have a bit of a special need, and need to know if anyone
knows the solution to this;

I need a sequence that is common to several tables - a "data id" that
gives a sort of unique object number to every row in every table. Some
associated tables (a documents table that can contain attachments to
most any model to be exact) need this id as their foreign key

create_table "projects", :force => true do |t|
	t.column "data_id", :serial							t.column "parent_id", :int
	t.column "customer_id", :int
	t.column "property_owner_id", :int
	t.column "name", :string
	t.column "long_description", :text
	t.column "created", :datetime

Now, I've done this all wrong, I know. The data_id field represented
here creates a new sequence for each table, in this case named
"projects_data_id_seq". I need all tables to use the same, preexisting
sequence (data_id_seq).

Do I need to specify the sql for this? Can anybody help me? :)

Thanks :)

Henning K. Pedersen   | prosjektleder
mopo as                   | mobil  41 14 23 75
                           | kontor 75 80 20 81
                           | epost  removed_email_address@domain.invalid
                           | www

mopo: √łkt frihet? gjennom fri programvare!
This topic is locked and can not be replied to.