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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F47c29fe9ff9abca279419c0d10f607e?d=identicon&s=25 Henning Kilset Pedersen (Guest)
on 2005-12-20 10:11
(Received via mailing list)
Hello.

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
counterpart.

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
end

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 Kilset Pedersen   | prosjektleder
mopo as                   | mobil  41 14 23 75
                           | kontor 75 80 20 81
                           | epost  henning@mopo.no
                           | www    http://mopo.no/

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