activerecord-redshift-adapter 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -21,4 +21,6 @@ spec/dummy/log/*.log
21
21
  spec/dummy/tmp/
22
22
  spec/dummy/.sass-cache
23
23
  spec/dummy/config/database.yml
24
- spec/dummy/db/schema.rb
24
+ spec/dummy/db/schema.rb
25
+
26
+ Gemfile.lock
@@ -18,4 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.homepage = 'http://github.com/fiksu/activerecord-redshift-adapter'
19
19
  s.add_dependency "pg"
20
20
  s.add_dependency "rails", '>= 3.0.0'
21
+ s.add_development_dependency 'rspec'
21
22
  end
@@ -37,6 +37,10 @@ module ActiveRecord
37
37
  super(name, self.class.extract_value_from_default(default), sql_type, null)
38
38
  end
39
39
 
40
+ def ==(other)
41
+ name == other.name && default == other.default && sql_type == other.sql_type && null == other.null
42
+ end
43
+
40
44
  # :stopdoc:
41
45
  class << self
42
46
  attr_accessor :money_precision
@@ -766,8 +770,8 @@ module ActiveRecord
766
770
 
767
771
  # Returns the list of all tables in the schema search path or a specified schema.
768
772
  def tables(name = nil)
769
- query(<<-SQL, 'SCHEMA').map { |row| row[0] }
770
- SELECT tablename
773
+ query(<<-SQL, 'SCHEMA').map { |row| "#{row[0]}.#{row[1]}" }
774
+ SELECT schemaname, tablename
771
775
  FROM pg_tables
772
776
  WHERE schemaname = ANY (current_schemas(false))
773
777
  SQL
@@ -804,41 +808,7 @@ module ActiveRecord
804
808
 
805
809
  # Returns an array of indexes for the given table.
806
810
  def indexes(table_name, name = nil)
807
- result = query(<<-SQL, 'SCHEMA')
808
- SELECT distinct i.relname, d.indisunique, d.indkey, pg_get_indexdef(d.indexrelid), t.oid
809
- FROM pg_class t
810
- INNER JOIN pg_index d ON t.oid = d.indrelid
811
- INNER JOIN pg_class i ON d.indexrelid = i.oid
812
- WHERE i.relkind = 'i'
813
- AND d.indisprimary = 'f'
814
- AND t.relname = '#{table_name}'
815
- AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = ANY (current_schemas(false)) )
816
- ORDER BY i.relname
817
- SQL
818
-
819
-
820
- result.map do |row|
821
- index_name = row[0]
822
- unique = row[1] == 't'
823
- indkey = row[2].split(" ")
824
- inddef = row[3]
825
- oid = row[4]
826
-
827
- columns = Hash[query(<<-SQL, "SCHEMA")]
828
- SELECT a.attnum, a.attname
829
- FROM pg_attribute a
830
- WHERE a.attrelid = #{oid}
831
- AND a.attnum IN (#{indkey.join(",")})
832
- SQL
833
-
834
- column_names = columns.values_at(*indkey).compact
835
-
836
- # add info on sort order for columns (only desc order is explicitly specified, asc is the default)
837
- desc_order_columns = inddef.scan(/(\w+) DESC/).flatten
838
- orders = desc_order_columns.any? ? Hash[desc_order_columns.map {|order_column| [order_column, :desc]}] : {}
839
-
840
- column_names.empty? ? nil : IndexDefinition.new(table_name, index_name, unique, column_names, [], orders)
841
- end.compact
811
+ []
842
812
  end
843
813
 
844
814
  # Returns the list of all column definitions for a table.
@@ -1036,12 +1006,14 @@ module ActiveRecord
1036
1006
  execute "ALTER TABLE #{quote_table_name(table_name)} RENAME COLUMN #{quote_column_name(column_name)} TO #{quote_column_name(new_column_name)}"
1037
1007
  end
1038
1008
 
1009
+ def add_index(*)
1010
+ # XXX nothing to do
1011
+ end
1012
+
1039
1013
  def remove_index!(table_name, index_name) #:nodoc:
1040
- execute "DROP INDEX #{quote_table_name(index_name)}"
1041
1014
  end
1042
1015
 
1043
1016
  def rename_index(table_name, old_name, new_name)
1044
- execute "ALTER INDEX #{quote_column_name(old_name)} RENAME TO #{quote_table_name(new_name)}"
1045
1017
  end
1046
1018
 
1047
1019
  def index_name_length
@@ -1,4 +1,4 @@
1
1
  module ActiverecordRedshiftAdapter
2
2
  # the current version of this gem
3
- VERSION = "0.8.0"
3
+ VERSION = "0.9.0"
4
4
  end
@@ -0,0 +1,8 @@
1
+ require "spec_helper"
2
+
3
+ describe ActiveRecord::Base do
4
+ it "opens a connection" do
5
+ connection = ActiveRecord::Base.redshift_connection(TEST_CONNECTION_HASH)
6
+ connection.active?.should be_true
7
+ end
8
+ end
@@ -0,0 +1,97 @@
1
+ require "spec_helper"
2
+
3
+ describe ActiveRecord::ConnectionAdapters::RedshiftAdapter do
4
+ before(:all) do
5
+ @connection = ActiveRecord::Base.redshift_connection(TEST_CONNECTION_HASH)
6
+
7
+ @connection.query <<-sql
8
+ CREATE TABLE public.test ( "id" INTEGER NULL, "name" VARCHAR(80) NULL );
9
+ CREATE TABLE public.test2 ( "id" INTEGER, "name" VARCHAR );
10
+ INSERT INTO public.test VALUES (1, 'first');
11
+ INSERT INTO public.test VALUES (2, 'second');
12
+ CREATE TABLE test.test ( "id" INTEGER NOT NULL, "is" BOOL NOT NULL );
13
+ CREATE TABLE test.test2 ( "id" INTEGER, "is" BOOL );
14
+ sql
15
+ end
16
+
17
+ after(:all) do
18
+ @connection.query <<-sql
19
+ DROP TABLE public.test, public.test2, test.test, test.test2;
20
+ sql
21
+ end
22
+
23
+ describe "#initialize" do
24
+ it "opens a connection" do
25
+ @connection.active?.should be_true
26
+ end
27
+ end
28
+
29
+ describe "#tables" do
30
+ it "returns all tables in public schema" do
31
+ @connection.schema_search_path = "public"
32
+ @connection.tables.should == ["public.test", "public.test2"]
33
+ end
34
+
35
+ it "returns all tables in all schemas" do
36
+ @connection.schema_search_path = "public, test"
37
+ @connection.tables.should == ["public.test", "public.test2", "test.test", "test.test2"]
38
+ end
39
+ end
40
+
41
+ describe "#columns" do
42
+ it "returns all columns in table in public schema" do
43
+ id = ActiveRecord::ConnectionAdapters::RedshiftColumn.new("id", "", "integer", true)
44
+ name = ActiveRecord::ConnectionAdapters::RedshiftColumn.new("name", "", "character varying(80)", true)
45
+ @connection.columns("test").should == [id, name]
46
+ end
47
+
48
+ it "returns all columns in table" do
49
+ id = ActiveRecord::ConnectionAdapters::RedshiftColumn.new("id", "", "integer", false)
50
+ is = ActiveRecord::ConnectionAdapters::RedshiftColumn.new("is", "", "boolean", false)
51
+ @connection.columns("test.test").should == [id, is]
52
+ end
53
+ end
54
+
55
+ describe "#table_exists?" do
56
+ it "checks if table in schema exists" do
57
+ @connection.table_exists?("public.test").should be_true
58
+ end
59
+
60
+ it "checks if unknown table in schema doesn't exist" do
61
+ @connection.table_exists?("public.null").should be_false
62
+ end
63
+
64
+ it "checks if table in implied schema exists" do
65
+ @connection.table_exists?("test2").should be_true
66
+ end
67
+ end
68
+
69
+ describe "#current_database" do
70
+ it "returns current database" do
71
+ @connection.current_database.should == TEST_CONNECTION_HASH[:database]
72
+ end
73
+ end
74
+
75
+ describe "#schema_search_path" do
76
+ it "returns current database" do
77
+ @connection.schema_search_path = '"$user", public'
78
+ @connection.schema_search_path.should == '"$user", public'
79
+ end
80
+ end
81
+
82
+ describe "#update_sql" do
83
+ it "returns the number of updated rows" do
84
+ @connection.update_sql("UPDATE public.test SET name = 'test'").should == 2
85
+ end
86
+ end
87
+
88
+ describe "#quote_string" do
89
+ it "quotes the string without surrouding quotes" do
90
+ @connection.quote_string("quote'd").should == "quote''d"
91
+ end
92
+
93
+ it "returns identical string when no quoting is required" do
94
+ @connection.quote_string("quote").should == "quote"
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,10 @@
1
+ # CREATE USER test_user WITH PASSWORD 'test_password';
2
+ # CREATE SCHEMA test AUTHORIZATION test_user;
3
+ host: CLUSTERNAME.IDENTIFIER.REGION.redshift.amazonaws.com
4
+ port: 5432
5
+ username: test_user
6
+ password: test_password
7
+ database: dev
8
+ # ssl: true
9
+ # search_path:
10
+ # role:
@@ -0,0 +1,33 @@
1
+ require "active_record"
2
+ require "yaml"
3
+ require "active_record/connection_adapters/redshift_adapter"
4
+
5
+ # This file was generated by the `rspec --init` command. Conventionally, all
6
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
7
+ # Require this file using `require "spec_helper"` to ensure that it is only
8
+ # loaded once.
9
+ #
10
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+
16
+ # Run specs in random order to surface order dependencies. If you find an
17
+ # order dependency and want to debug it, you can fix the order by providing
18
+ # the seed, which is printed after each run.
19
+ # --seed 1234
20
+ config.order = 'random'
21
+ end
22
+
23
+ TEST_CONNECTION_FILENAME = File.expand_path("../dummy/config/database.yml", __FILE__)
24
+
25
+ if File.exist?(TEST_CONNECTION_FILENAME)
26
+ TEST_CONNECTION_HASH = YAML.load(File.read(TEST_CONNECTION_FILENAME)).with_indifferent_access
27
+ else
28
+ puts
29
+ puts "Create #{TEST_CONNECTION_FILENAME} with connection info "
30
+ puts "for your Redshift test database in order to run the test suite."
31
+ puts
32
+ exit(1)
33
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-redshift-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: 3.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  description: This gem provides the Rails 3 with database adapter for AWS RedShift.
47
63
  email: keith@fiksu.com
48
64
  executables: []
@@ -58,6 +74,10 @@ files:
58
74
  - lib/active_record/connection_adapters/redshift_adapter.rb
59
75
  - lib/activerecord_redshift_adapter.rb
60
76
  - lib/activerecord_redshift_adapter/version.rb
77
+ - spec/active_record/base_spec.rb
78
+ - spec/active_record/connection_adapters/redshift_adapter_spec.rb
79
+ - spec/dummy/config/database.example.yml
80
+ - spec/spec_helper.rb
61
81
  homepage: http://github.com/fiksu/activerecord-redshift-adapter
62
82
  licenses:
63
83
  - New BSD License
@@ -79,8 +99,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
99
  version: '0'
80
100
  requirements: []
81
101
  rubyforge_project:
82
- rubygems_version: 1.8.24
102
+ rubygems_version: 1.8.25
83
103
  signing_key:
84
104
  specification_version: 3
85
105
  summary: Rails 3 database adapter support for AWS RedShift.
86
- test_files: []
106
+ test_files:
107
+ - spec/active_record/base_spec.rb
108
+ - spec/active_record/connection_adapters/redshift_adapter_spec.rb
109
+ - spec/dummy/config/database.example.yml
110
+ - spec/spec_helper.rb