Db/schema.rb and PostgreSQL sequences

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? :slight_smile:

Thanks :slight_smile:


Henning K. Pedersen | prosjektleder
mopo as | mobil 41 14 23 75
| kontor 75 80 20 81
| epost [email protected]
| www http://mopo.no/

mopo: økt frihet? gjennom fri programvare!