rails/rails — pull request #14719 by pavelbrylov (2014-04-12 15:39:47+00:00)
Title: Fix for reset_pk_sequence! which appears to be broken for postgres schemas

When using postgres with schemas in rails, testing is broken because it is failing to reset primary key sequence.
Assume I have documents.files table (table name is files, schema name is documents), running `rake test` with empty fixtures would fail with:
```sql
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "files_id_seq" does not exist
LINE 1: ...LECT COALESCE(MAX("id")+(SELECT increment_by FROM "files_id_...
^
: SELECT setval('"files_id_seq"', (SELECT COALESCE(MAX("id")+(SELECT increment_by FROM "files_id_seq"), (SELECT min_value FROM "files_id_seq")) FROM "documents"."files"), false)
```
Thing is that schema-specific sequences are accessed with schema name as a prefix, so in this case correct query would be:
```sql
SELECT setval('"documents"."files_id_seq"', (SELECT COALESCE(MAX("id")+(SELECT increment_by FROM "documents"."files_id_seq"), (SELECT min_value FROM "documents"."files_id_seq")) FROM "documents"."files"), false);
```

Simple and straightforward fix attached.