Giter Club home page Giter Club logo

activerecord4-redshift-adapter's Introduction

activerecord4-redshift-adapter

Amazon Redshift adapter for ActiveRecord 4 (Rails 4). Almost all code are copied from ActiveRecord 4.2.0 PostgreSQL driver and modified for Redshift.

Forked and heavily modified from (https://github.com/aamine/activerecord4-redshift-adapter).

How to Use

In Gemfile

gem 'activerecord4-redshift-adapter', github: 'khwangster/activerecord4-redshift-adapter'

In database.yml

development:
  adapter: redshift
  host: your_cluster_name.ident.ap-east-1.redshift.amazonaws.com
  database: dev
  port: 5439
  username: your_user
  password: your_password
  encoding: utf-8
  pool: 3
  timeout: 5000

License

MIT license (same as ActiveRecord)

activerecord4-redshift-adapter's People

Contributors

aamine avatar khwangster avatar pehrlich avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

activerecord4-redshift-adapter's Issues

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

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

Undefined method `type' for "character varying(256)":String

Hi, thanks for all your work on this adapter. ๐Ÿ‘ With it I am able to connect to redshift and run some simple queries. However, other simple queries fail. I have a table with nothing but varchar columns:

psql (9.3.5, server 8.0.2)
SSL connection (cipher: ECDHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.

production=> \d users
                   Column                    |          Type          | Modifiers 
-------------------------------------------+------------------------+-----------
 education                                   | character varying(256) | 
 occupation                                  | character varying(256) | 
 state                                       | character varying(256) | 
...

If I try to query these columns I get an error that seems to indicate that the column type isn't recognized properly:

[3] pry(main)> User.count
D, [2014-10-24T10:29:44.499199 #11922] DEBUG -- :    (609.7ms)  SELECT COUNT(*) FROM "users"
=> 20000000
[5] pry(main)> User.where(state: 'FL').limit(1).first
NoMethodError: undefined method `type' for "character varying(256)":String
from /home/bram/Code/redshift/.bundle/bundle/ruby/2.1.0/gems/activerecord-4.2.0.beta2/lib/active_record/connection_adapters/column.rb:18:in `type'

Any ideas? I'm not familiar with AR internals regarding type casting. I'm going to dig in the next chance I get, but maybe you have some idea since you wrote it.

And here is the full stack trace:

/home/bram/Code/redshift/.bundle/bundle/ruby/2.1.0/gems/activerecord-4.2.0.beta2/lib/active_record/connection_adapters/column.rb:18:in `type': undefined method `type' for "character varying(256)":String (NoMethodError)
from /home/bram/Code/redshift/.bundle/bundle/ruby/2.1.0/bundler/gems/activerecord4-redshift-adapter-028cf947a713/lib/active_record/connection_adapters/redshift/quoting.rb:21:in `quote'
from /home/bram/Code/redshift/.bundle/bundle/ruby/2.1.0/gems/activerecord-4.2.0.beta2/lib/active_record/connection_adapters/abstract_adapter.rb:118:in `block in compile'
from /home/bram/Code/redshift/.bundle/bundle/ruby/2.1.0/gems/activerecord-4.2.0.beta2/lib/active_record/connection_adapters/abstract_adapter.rb:118:in `map'
from /home/bram/Code/redshift/.bundle/bundle/ruby/2.1.0/gems/activerecord-4.2.0.beta2/lib/active_record/connection_adapters/abstract_adapter.rb:118:in `compile'
from /home/bram/Code/redshift/.bundle/bundle/ruby/2.1.0/gems/activerecord-4.2.0.beta2/lib/active_record/connection_adapters/abstract/database_statements.rb:13:in `to_sql'
from /home/bram/Code/redshift/.bundle/bundle/ruby/2.1.0/gems/activerecord-4.2.0.beta2/lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
from /home/bram/Code/redshift/.bundle/bundle/ruby/2.1.0/gems/activerecord-4.2.0.beta2/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
from /home/bram/Code/redshift/.bundle/bundle/ruby/2.1.0/gems/activerecord-4.2.0.beta2/lib/active_record/querying.rb:39:in `find_by_sql'
from /home/bram/Code/redshift/.bundle/bundle/ruby/2.1.0/gems/activerecord-4.2.0.beta2/lib/active_record/relation.rb:635:in `exec_queries'
from /home/bram/Code/redshift/.bundle/bundle/ruby/2.1.0/gems/activerecord-4.2.0.beta2/lib/active_record/relation.rb:511:in `load'
from /home/bram/Code/redshift/.bundle/bundle/ruby/2.1.0/gems/activerecord-4.2.0.beta2/lib/active_record/relation.rb:241:in `to_a'
from /home/bram/Code/redshift/.bundle/bundle/ruby/2.1.0/gems/activerecord-4.2.0.beta2/lib/active_record/relation/finder_methods.rb:500:in `find_nth_with_limit'
from /home/bram/Code/redshift/.bundle/bundle/ruby/2.1.0/gems/activerecord-4.2.0.beta2/lib/active_record/relation/finder_methods.rb:488:in `find_nth'
from /home/bram/Code/redshift/.bundle/bundle/ruby/2.1.0/gems/activerecord-4.2.0.beta2/lib/active_record/relation/finder_methods.rb:134:in `first'
from lib/models.rb:21:in `<main>'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.