# Sequence name prefix

**URL:** <https://www.ruby-forum.com/t/sequence-name-prefix/107217>\
**Category:** Rails\
**Created:** [June 19, 2007, 11:13am UTC](https://www.ruby-forum.com/t/sequence-name-prefix/107217 "2007-06-19T11:13:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![isaphan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/5e9695/32.png) [@isaphan](https://www.ruby-forum.com/u/isaphan)\
**Post date:** [June 19, 2007, 11:13am UTC](https://www.ruby-forum.com/t/sequence-name-prefix/107217/1 "2007-06-19T11:13:25Z")

</div>

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.’ ☹

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

---

<div class="post-metadata">

**Author:** ![isaphan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/5e9695/32.png) [@isaphan](https://www.ruby-forum.com/u/isaphan)\
**Post date:** [June 20, 2007, 6:10am UTC](https://www.ruby-forum.com/t/sequence-name-prefix/107217/2 "2007-06-20T06:10:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![isaphan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/5e9695/32.png) [@isaphan](https://www.ruby-forum.com/u/isaphan)\
**Post date:** [June 20, 2007, 9:54am UTC](https://www.ruby-forum.com/t/sequence-name-prefix/107217/3 "2007-06-20T09:54:44Z")

</div>

many thanks Michael, that did it 🙂

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