khwangster / activerecord4-redshift-adapter

ActiveRecord 4 DB adapter for Amazon Redshift
MIT License
3 stars 4 forks source link

Cannot dump schema: `cannot cast type regclass to character varying` #2

Open pehrlich opened 9 years ago

pehrlich commented 9 years ago

Hi

It looks like you're just maintaining this branch for your own self, but I'm curious if you've run in to this error, or perhaps have any ideas on its background:

> foreman run rake db:schema:dump
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:23: warning: already initialized constant ActiveRecord::ConnectionHandling::VALID_CONN_PARAMS
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bundler/gems/activerecord4-redshift-adapter-37d00832b906/lib/active_record/connection_adapters/redshift_adapter.rb:23: warning: previous definition of VALID_CONN_PARAMS was here
rake aborted!
ActiveRecord::StatementInvalid: PG::CannotCoerce: ERROR:  cannot cast type regclass to character varying
: SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
FROM pg_constraint c
JOIN pg_class t1 ON c.conrelid = t1.oid
JOIN pg_class t2 ON c.confrelid = t2.oid
JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid
JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid
JOIN pg_namespace t3 ON c.connamespace = t3.oid
WHERE c.contype = 'f'
  AND t1.relname = 'jobs.'
  AND t3.nspname = ANY (current_schemas(false))
ORDER BY c.conname
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bundler/gems/activerecord4-redshift-adapter-37d00832b906/lib/active_record/connection_adapters/redshift_adapter.rb:581:in `async_exec'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bundler/gems/activerecord4-redshift-adapter-37d00832b906/lib/active_record/connection_adapters/redshift_adapter.rb:581:in `block in exec_no_cache'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `block in log'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract_adapter.rb:460:in `log'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bundler/gems/activerecord4-redshift-adapter-37d00832b906/lib/active_record/connection_adapters/redshift_adapter.rb:581:in `exec_no_cache'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bundler/gems/activerecord4-redshift-adapter-37d00832b906/lib/active_record/connection_adapters/redshift_adapter.rb:573:in `execute_and_clear'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bundler/gems/activerecord4-redshift-adapter-37d00832b906/lib/active_record/connection_adapters/redshift/database_statements.rb:160:in `exec_query'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:336:in `select'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bundler/gems/activerecord4-redshift-adapter-37d00832b906/lib/active_record/connection_adapters/redshift/schema_statements.rb:459:in `foreign_keys'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/schema_dumper.rb:212:in `foreign_keys'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/schema_dumper.rb:103:in `block in tables'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/schema_dumper.rb:102:in `each'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/schema_dumper.rb:102:in `tables'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/schema_dumper.rb:38:in `dump'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/schema_dumper.rb:22:in `dump'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:237:in `block (4 levels) in <top (required)>'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:236:in `open'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:236:in `block (3 levels) in <top (required)>'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `eval'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `<main>'
PG::CannotCoerce: ERROR:  cannot cast type regclass to character varying
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bundler/gems/activerecord4-redshift-adapter-37d00832b906/lib/active_record/connection_adapters/redshift_adapter.rb:581:in `async_exec'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bundler/gems/activerecord4-redshift-adapter-37d00832b906/lib/active_record/connection_adapters/redshift_adapter.rb:581:in `block in exec_no_cache'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `block in log'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract_adapter.rb:460:in `log'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bundler/gems/activerecord4-redshift-adapter-37d00832b906/lib/active_record/connection_adapters/redshift_adapter.rb:581:in `exec_no_cache'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bundler/gems/activerecord4-redshift-adapter-37d00832b906/lib/active_record/connection_adapters/redshift_adapter.rb:573:in `execute_and_clear'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bundler/gems/activerecord4-redshift-adapter-37d00832b906/lib/active_record/connection_adapters/redshift/database_statements.rb:160:in `exec_query'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:336:in `select'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bundler/gems/activerecord4-redshift-adapter-37d00832b906/lib/active_record/connection_adapters/redshift/schema_statements.rb:459:in `foreign_keys'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/schema_dumper.rb:212:in `foreign_keys'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/schema_dumper.rb:103:in `block in tables'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/schema_dumper.rb:102:in `each'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/schema_dumper.rb:102:in `tables'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/schema_dumper.rb:38:in `dump'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/schema_dumper.rb:22:in `dump'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:237:in `block (4 levels) in <top (required)>'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:236:in `open'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:236:in `block (3 levels) in <top (required)>'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `eval'
/Users/pehrlich/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:schema:dump
(See full trace by running task with --trace)

This is of course a little important, as a schema:dump tends to happen after every db:migrate.

Thanks, --Peter

PS - Had you run in to any primary key naming issues? https://github.com/aamine/activerecord4-redshift-adapter/pull/10/files#r17226927

khwangster commented 9 years ago

Hello.

I personally have never run migrations with this gem; there are definitely sections of the adapter that looks like it probably would not work on Redshift (most notably index specific functionality, but that doesn't seem to be the cause of this issue). I'll look into this in more detail next chance I get.

pehrlich commented 9 years ago

Of course see this, which seems to fix all the in-your-face issues: https://github.com/khwangster/activerecord4-redshift-adapter/pull/3

Cheers