Sequence name prefix

In Postgres, I use different database schemas for each application, by
declaring, e.g.:

class ApplicationController < ActionController::Base
ActiveRecord::Base.table_name_prefix = “keywords.”
end

I assumed that the sequence names were also prefixed with the database
schema names, e.g.

keywords.things_id_seq

But Rails 1.2.3 assumes the sequence is NOT in the same schema as the
tables, and prefixes them with ‘public.’ :frowning:

I have to declare in ALL my classes:

set_sequence_name "keywords.things_id_seq"

This is awful in terms of maintenance. So I would be very grateful if I
could find an equivalent of:

ActiveRecord::Base.sequence_name_prefix = “keywords.”

(this fails: undefined method `sequence_name_prefix=’ for
ActiveRecord::Base:Class)

Any help very much appreciated.

Isabelle

On Jun 19, 2007, at 4:13 , Isabelle P. wrote:

In Postgres, I use different database schemas for each application, by
declaring, e.g.:

class ApplicationController < ActionController::Base
ActiveRecord::Base.table_name_prefix = “keywords.”
end

Rather than prefixing your table names with the schema name, add the
schema you want to schema_search_path in your database.yml file. Your
tables (and other database objects, such as sequences and indexes)
will be created in that schema. For example, if you want your app to
be located in the myapp schema:

schema_search_path: myapp,public

Be sure to include the public schema (after the myapp schema) as well.

You might want to check the database and make sure the tables you’ve
created so far are where you think they are. They might be named
“keywords.foo” (in the public schema) rather than “keywords”.“foo”,
which is how schema + table names are actually represented in
Postgres. I haven’t checked how the PostgreSQL adapter quotes table
and and column names, but it could be an issue.

Michael G.
grzm seespotcode net

many thanks Michael, that did it :slight_smile:

I hadn’t thought of looking into
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter