PostgreSQL schema dumper does not support capitalized table names

We have a legacy database that has been migrated to PostgreSQL and includes camel-case table names. When running migrations, the schema dumper throws an error when it encounters these tables. I believe I've created and tested the proper solution to this in the postgresql adapter. Please see the following ticket for details:

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2418-postgresql-schema-dumper-does-not-support-capitalized-table-names

I would appreciate it if someone could take a look at the patch and tests and see if there should be any other improvements.

Thanks! Scott

We have a legacy database that has been migrated to PostgreSQL and includes camel-case table names. When running migrations, the schema dumper throws an error when it encounters these tables. I believe I've created and tested the proper solution to this in the postgresql adapter. Please see the following ticket for details:

#2418 PostgreSQL schema dumper does not support capitalized table names - Ruby on Rails - rails

I would appreciate it if someone could take a look at the patch and tests and see if there should be any other improvements.

+ # The name is a string. It could contain a schema, which shouldn't + # be included in the quotes. + schema, table_name = name.split('.') + if schema && table_name + %(#{schema}."#{table_name}")

You're not quoting the schema name?

Regards, Isak

Correct. Apparently the schema name should not be included in the quotes. Here's an example (PostgreSQL 8.2.11):

test=# create schema schema_test create table "CamelCase" (id integer primary key); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "CamelCase_pkey" for table "CamelCase" CREATE SCHEMA

test=# select 'schema_test.CamelCase'::regclass; ERROR: relation "schema_test.camelcase" does not exist

test=# select '"schema_test.CamelCase"'::regclass; ERROR: relation "schema_test.CamelCase" does not exist

test=# select 'schema_test."CamelCase"'::regclass;         regclass

Ticket #390 just got resolved and committed, which implements more complete table name quoting than I had:

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/390-postgres-adapter-quotes-table-name-breaks-when-non-default-schema-is-used

However, that patch still doesn't quote table names when casting to regclass, so I've adjusted my patch so that it uses the new quote_table_name method instead. I also integrated my tests with the new patch. Here's my new patch:

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2418-postgresql-schema-dumper-does-not-support-capitalized-table-names#ticket-2418-3

So to summarize, ticket #390 implemented table quoting to allow non- default schemas to be specified. My ticket #2418 now piggybacks on that to prevent a PGError when capitalized table names are used.

I've tested this on MacOS 10.5 using PostgreSQL 8.2.11 and each of the "pg" and "postgres" gems. I'd appreciate it if others could verify this (or other platforms) as well.

Thanks, Scott