activerecord-redshift-adapter 0.9.12 → 8.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +5 -13
  2. data/LICENSE +25 -1
  3. data/README.md +28 -86
  4. data/lib/active_record/connection_adapters/redshift_7_0/array_parser.rb +92 -0
  5. data/lib/active_record/connection_adapters/redshift_7_0/column.rb +17 -0
  6. data/lib/active_record/connection_adapters/redshift_7_0/database_statements.rb +232 -0
  7. data/lib/active_record/connection_adapters/redshift_7_0/oid/date_time.rb +36 -0
  8. data/lib/active_record/connection_adapters/redshift_7_0/oid/decimal.rb +15 -0
  9. data/lib/active_record/connection_adapters/redshift_7_0/oid/json.rb +41 -0
  10. data/lib/active_record/connection_adapters/redshift_7_0/oid/jsonb.rb +25 -0
  11. data/lib/active_record/connection_adapters/redshift_7_0/oid/type_map_initializer.rb +62 -0
  12. data/lib/active_record/connection_adapters/redshift_7_0/oid.rb +17 -0
  13. data/lib/active_record/connection_adapters/redshift_7_0/quoting.rb +99 -0
  14. data/lib/active_record/connection_adapters/redshift_7_0/referential_integrity.rb +17 -0
  15. data/lib/active_record/connection_adapters/redshift_7_0/schema_definitions.rb +70 -0
  16. data/lib/active_record/connection_adapters/redshift_7_0/schema_dumper.rb +17 -0
  17. data/lib/active_record/connection_adapters/redshift_7_0/schema_statements.rb +421 -0
  18. data/lib/active_record/connection_adapters/redshift_7_0/type_metadata.rb +39 -0
  19. data/lib/active_record/connection_adapters/redshift_7_0/utils.rb +81 -0
  20. data/lib/active_record/connection_adapters/redshift_7_0_adapter.rb +768 -0
  21. data/lib/active_record/connection_adapters/redshift_7_1/array_parser.rb +92 -0
  22. data/lib/active_record/connection_adapters/redshift_7_1/column.rb +17 -0
  23. data/lib/active_record/connection_adapters/redshift_7_1/database_statements.rb +180 -0
  24. data/lib/active_record/connection_adapters/redshift_7_1/oid/date_time.rb +36 -0
  25. data/lib/active_record/connection_adapters/redshift_7_1/oid/decimal.rb +15 -0
  26. data/lib/active_record/connection_adapters/redshift_7_1/oid/json.rb +41 -0
  27. data/lib/active_record/connection_adapters/redshift_7_1/oid/jsonb.rb +25 -0
  28. data/lib/active_record/connection_adapters/redshift_7_1/oid/type_map_initializer.rb +62 -0
  29. data/lib/active_record/connection_adapters/redshift_7_1/oid.rb +17 -0
  30. data/lib/active_record/connection_adapters/redshift_7_1/quoting.rb +161 -0
  31. data/lib/active_record/connection_adapters/redshift_7_1/referential_integrity.rb +17 -0
  32. data/lib/active_record/connection_adapters/redshift_7_1/schema_definitions.rb +70 -0
  33. data/lib/active_record/connection_adapters/redshift_7_1/schema_dumper.rb +17 -0
  34. data/lib/active_record/connection_adapters/redshift_7_1/schema_statements.rb +422 -0
  35. data/lib/active_record/connection_adapters/redshift_7_1/type_metadata.rb +43 -0
  36. data/lib/active_record/connection_adapters/redshift_7_1/utils.rb +81 -0
  37. data/lib/active_record/connection_adapters/redshift_7_1_adapter.rb +847 -0
  38. data/lib/active_record/connection_adapters/redshift_7_2/array_parser.rb +92 -0
  39. data/lib/active_record/connection_adapters/redshift_7_2/column.rb +17 -0
  40. data/lib/active_record/connection_adapters/redshift_7_2/database_statements.rb +180 -0
  41. data/lib/active_record/connection_adapters/redshift_7_2/oid/date_time.rb +36 -0
  42. data/lib/active_record/connection_adapters/redshift_7_2/oid/decimal.rb +15 -0
  43. data/lib/active_record/connection_adapters/redshift_7_2/oid/json.rb +41 -0
  44. data/lib/active_record/connection_adapters/redshift_7_2/oid/jsonb.rb +25 -0
  45. data/lib/active_record/connection_adapters/redshift_7_2/oid/type_map_initializer.rb +62 -0
  46. data/lib/active_record/connection_adapters/redshift_7_2/oid.rb +17 -0
  47. data/lib/active_record/connection_adapters/redshift_7_2/quoting.rb +164 -0
  48. data/lib/active_record/connection_adapters/redshift_7_2/referential_integrity.rb +17 -0
  49. data/lib/active_record/connection_adapters/redshift_7_2/schema_definitions.rb +70 -0
  50. data/lib/active_record/connection_adapters/redshift_7_2/schema_dumper.rb +17 -0
  51. data/lib/active_record/connection_adapters/redshift_7_2/schema_statements.rb +422 -0
  52. data/lib/active_record/connection_adapters/redshift_7_2/type_metadata.rb +43 -0
  53. data/lib/active_record/connection_adapters/redshift_7_2/utils.rb +81 -0
  54. data/lib/active_record/connection_adapters/redshift_7_2_adapter.rb +847 -0
  55. data/lib/active_record/connection_adapters/redshift_8_0/array_parser.rb +92 -0
  56. data/lib/active_record/connection_adapters/redshift_8_0/column.rb +17 -0
  57. data/lib/active_record/connection_adapters/redshift_8_0/database_statements.rb +181 -0
  58. data/lib/active_record/connection_adapters/redshift_8_0/oid/date_time.rb +36 -0
  59. data/lib/active_record/connection_adapters/redshift_8_0/oid/decimal.rb +15 -0
  60. data/lib/active_record/connection_adapters/redshift_8_0/oid/json.rb +41 -0
  61. data/lib/active_record/connection_adapters/redshift_8_0/oid/jsonb.rb +25 -0
  62. data/lib/active_record/connection_adapters/redshift_8_0/oid/type_map_initializer.rb +62 -0
  63. data/lib/active_record/connection_adapters/redshift_8_0/oid.rb +17 -0
  64. data/lib/active_record/connection_adapters/redshift_8_0/quoting.rb +164 -0
  65. data/lib/active_record/connection_adapters/redshift_8_0/referential_integrity.rb +17 -0
  66. data/lib/active_record/connection_adapters/redshift_8_0/schema_definitions.rb +70 -0
  67. data/lib/active_record/connection_adapters/redshift_8_0/schema_dumper.rb +17 -0
  68. data/lib/active_record/connection_adapters/redshift_8_0/schema_statements.rb +422 -0
  69. data/lib/active_record/connection_adapters/redshift_8_0/type_metadata.rb +43 -0
  70. data/lib/active_record/connection_adapters/redshift_8_0/utils.rb +81 -0
  71. data/lib/active_record/connection_adapters/redshift_8_0_adapter.rb +846 -0
  72. data/lib/active_record/connection_adapters/redshift_adapter.rb +13 -1286
  73. data/lib/active_record/tasks/redshift_7_0_tasks.rb +148 -0
  74. data/lib/active_record/tasks/redshift_7_1_tasks.rb +151 -0
  75. data/lib/active_record/tasks/redshift_7_2_tasks.rb +151 -0
  76. data/lib/active_record/tasks/redshift_8_0_tasks.rb +151 -0
  77. data/lib/active_record/tasks/redshift_tasks.rb +13 -0
  78. data/lib/activerecord-redshift-adapter.rb +13 -0
  79. metadata +110 -84
  80. data/.gitignore +0 -26
  81. data/Gemfile +0 -14
  82. data/Rakefile +0 -26
  83. data/activerecord-redshift-adapter.gemspec +0 -24
  84. data/lib/activerecord_redshift/table_manager.rb +0 -230
  85. data/lib/activerecord_redshift_adapter/version.rb +0 -4
  86. data/lib/activerecord_redshift_adapter.rb +0 -4
  87. data/lib/monkeypatch_activerecord.rb +0 -195
  88. data/lib/monkeypatch_arel.rb +0 -96
  89. data/spec/active_record/base_spec.rb +0 -37
  90. data/spec/active_record/connection_adapters/redshift_adapter_spec.rb +0 -97
  91. data/spec/dummy/config/database.example.yml +0 -12
  92. data/spec/spec_helper.rb +0 -33
metadata CHANGED
@@ -1,133 +1,159 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-redshift-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.12
4
+ version: 8.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
- - Keith Gabryelski
8
- autorequire:
7
+ - Janusz Mordarski
8
+ - Nancy Foen
9
+ - Minero Aoki
10
+ - iamdbc
11
+ - Quentin Rousseau
12
+ - Johan Le Bray
13
+ - Owen Stephens
14
+ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
- date: 2014-03-30 00:00:00.000000000 Z
17
+ date: 2024-11-25 00:00:00.000000000 Z
12
18
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: pg
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ! '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ! '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
19
  - !ruby/object:Gem::Dependency
28
20
  name: activerecord
29
21
  requirement: !ruby/object:Gem::Requirement
30
22
  requirements:
31
- - - ! '>='
23
+ - - ">="
32
24
  - !ruby/object:Gem::Version
33
- version: 3.0.0
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ! '>='
25
+ version: '7.0'
26
+ - - "<"
39
27
  - !ruby/object:Gem::Version
40
- version: 3.0.0
41
- - !ruby/object:Gem::Dependency
42
- name: activesupport
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ! '>='
46
- - !ruby/object:Gem::Version
47
- version: 3.0.0
28
+ version: '9.0'
48
29
  type: :runtime
49
30
  prerelease: false
50
31
  version_requirements: !ruby/object:Gem::Requirement
51
32
  requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: 3.0.0
55
- - !ruby/object:Gem::Dependency
56
- name: arel
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ! '>='
33
+ - - ">="
60
34
  - !ruby/object:Gem::Version
61
- version: 3.0.0
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ! '>='
35
+ version: '7.0'
36
+ - - "<"
67
37
  - !ruby/object:Gem::Version
68
- version: 3.0.0
38
+ version: '9.0'
69
39
  - !ruby/object:Gem::Dependency
70
- name: rspec
40
+ name: pg
71
41
  requirement: !ruby/object:Gem::Requirement
72
42
  requirements:
73
- - - ! '>='
43
+ - - "~>"
74
44
  - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
45
+ version: '1.0'
46
+ type: :runtime
77
47
  prerelease: false
78
48
  version_requirements: !ruby/object:Gem::Requirement
79
49
  requirements:
80
- - - ! '>='
50
+ - - "~>"
81
51
  - !ruby/object:Gem::Version
82
- version: '0'
83
- description: This gem provides the Rails 3 with database adapter for AWS RedShift.
84
- email: keith@fiksu.com
52
+ version: '1.0'
53
+ description: Amazon Redshift adapter for ActiveRecord 7+
54
+ email: janusz.m@gmail.com
85
55
  executables: []
86
56
  extensions: []
87
57
  extra_rdoc_files: []
88
58
  files:
89
- - .gitignore
90
- - Gemfile
91
59
  - LICENSE
92
60
  - README.md
93
- - Rakefile
94
- - activerecord-redshift-adapter.gemspec
61
+ - lib/active_record/connection_adapters/redshift_7_0/array_parser.rb
62
+ - lib/active_record/connection_adapters/redshift_7_0/column.rb
63
+ - lib/active_record/connection_adapters/redshift_7_0/database_statements.rb
64
+ - lib/active_record/connection_adapters/redshift_7_0/oid.rb
65
+ - lib/active_record/connection_adapters/redshift_7_0/oid/date_time.rb
66
+ - lib/active_record/connection_adapters/redshift_7_0/oid/decimal.rb
67
+ - lib/active_record/connection_adapters/redshift_7_0/oid/json.rb
68
+ - lib/active_record/connection_adapters/redshift_7_0/oid/jsonb.rb
69
+ - lib/active_record/connection_adapters/redshift_7_0/oid/type_map_initializer.rb
70
+ - lib/active_record/connection_adapters/redshift_7_0/quoting.rb
71
+ - lib/active_record/connection_adapters/redshift_7_0/referential_integrity.rb
72
+ - lib/active_record/connection_adapters/redshift_7_0/schema_definitions.rb
73
+ - lib/active_record/connection_adapters/redshift_7_0/schema_dumper.rb
74
+ - lib/active_record/connection_adapters/redshift_7_0/schema_statements.rb
75
+ - lib/active_record/connection_adapters/redshift_7_0/type_metadata.rb
76
+ - lib/active_record/connection_adapters/redshift_7_0/utils.rb
77
+ - lib/active_record/connection_adapters/redshift_7_0_adapter.rb
78
+ - lib/active_record/connection_adapters/redshift_7_1/array_parser.rb
79
+ - lib/active_record/connection_adapters/redshift_7_1/column.rb
80
+ - lib/active_record/connection_adapters/redshift_7_1/database_statements.rb
81
+ - lib/active_record/connection_adapters/redshift_7_1/oid.rb
82
+ - lib/active_record/connection_adapters/redshift_7_1/oid/date_time.rb
83
+ - lib/active_record/connection_adapters/redshift_7_1/oid/decimal.rb
84
+ - lib/active_record/connection_adapters/redshift_7_1/oid/json.rb
85
+ - lib/active_record/connection_adapters/redshift_7_1/oid/jsonb.rb
86
+ - lib/active_record/connection_adapters/redshift_7_1/oid/type_map_initializer.rb
87
+ - lib/active_record/connection_adapters/redshift_7_1/quoting.rb
88
+ - lib/active_record/connection_adapters/redshift_7_1/referential_integrity.rb
89
+ - lib/active_record/connection_adapters/redshift_7_1/schema_definitions.rb
90
+ - lib/active_record/connection_adapters/redshift_7_1/schema_dumper.rb
91
+ - lib/active_record/connection_adapters/redshift_7_1/schema_statements.rb
92
+ - lib/active_record/connection_adapters/redshift_7_1/type_metadata.rb
93
+ - lib/active_record/connection_adapters/redshift_7_1/utils.rb
94
+ - lib/active_record/connection_adapters/redshift_7_1_adapter.rb
95
+ - lib/active_record/connection_adapters/redshift_7_2/array_parser.rb
96
+ - lib/active_record/connection_adapters/redshift_7_2/column.rb
97
+ - lib/active_record/connection_adapters/redshift_7_2/database_statements.rb
98
+ - lib/active_record/connection_adapters/redshift_7_2/oid.rb
99
+ - lib/active_record/connection_adapters/redshift_7_2/oid/date_time.rb
100
+ - lib/active_record/connection_adapters/redshift_7_2/oid/decimal.rb
101
+ - lib/active_record/connection_adapters/redshift_7_2/oid/json.rb
102
+ - lib/active_record/connection_adapters/redshift_7_2/oid/jsonb.rb
103
+ - lib/active_record/connection_adapters/redshift_7_2/oid/type_map_initializer.rb
104
+ - lib/active_record/connection_adapters/redshift_7_2/quoting.rb
105
+ - lib/active_record/connection_adapters/redshift_7_2/referential_integrity.rb
106
+ - lib/active_record/connection_adapters/redshift_7_2/schema_definitions.rb
107
+ - lib/active_record/connection_adapters/redshift_7_2/schema_dumper.rb
108
+ - lib/active_record/connection_adapters/redshift_7_2/schema_statements.rb
109
+ - lib/active_record/connection_adapters/redshift_7_2/type_metadata.rb
110
+ - lib/active_record/connection_adapters/redshift_7_2/utils.rb
111
+ - lib/active_record/connection_adapters/redshift_7_2_adapter.rb
112
+ - lib/active_record/connection_adapters/redshift_8_0/array_parser.rb
113
+ - lib/active_record/connection_adapters/redshift_8_0/column.rb
114
+ - lib/active_record/connection_adapters/redshift_8_0/database_statements.rb
115
+ - lib/active_record/connection_adapters/redshift_8_0/oid.rb
116
+ - lib/active_record/connection_adapters/redshift_8_0/oid/date_time.rb
117
+ - lib/active_record/connection_adapters/redshift_8_0/oid/decimal.rb
118
+ - lib/active_record/connection_adapters/redshift_8_0/oid/json.rb
119
+ - lib/active_record/connection_adapters/redshift_8_0/oid/jsonb.rb
120
+ - lib/active_record/connection_adapters/redshift_8_0/oid/type_map_initializer.rb
121
+ - lib/active_record/connection_adapters/redshift_8_0/quoting.rb
122
+ - lib/active_record/connection_adapters/redshift_8_0/referential_integrity.rb
123
+ - lib/active_record/connection_adapters/redshift_8_0/schema_definitions.rb
124
+ - lib/active_record/connection_adapters/redshift_8_0/schema_dumper.rb
125
+ - lib/active_record/connection_adapters/redshift_8_0/schema_statements.rb
126
+ - lib/active_record/connection_adapters/redshift_8_0/type_metadata.rb
127
+ - lib/active_record/connection_adapters/redshift_8_0/utils.rb
128
+ - lib/active_record/connection_adapters/redshift_8_0_adapter.rb
95
129
  - lib/active_record/connection_adapters/redshift_adapter.rb
96
- - lib/activerecord_redshift/table_manager.rb
97
- - lib/activerecord_redshift_adapter.rb
98
- - lib/activerecord_redshift_adapter/version.rb
99
- - lib/monkeypatch_activerecord.rb
100
- - lib/monkeypatch_arel.rb
101
- - spec/active_record/base_spec.rb
102
- - spec/active_record/connection_adapters/redshift_adapter_spec.rb
103
- - spec/dummy/config/database.example.yml
104
- - spec/spec_helper.rb
105
- homepage: http://github.com/fiksu/activerecord-redshift-adapter
130
+ - lib/active_record/tasks/redshift_7_0_tasks.rb
131
+ - lib/active_record/tasks/redshift_7_1_tasks.rb
132
+ - lib/active_record/tasks/redshift_7_2_tasks.rb
133
+ - lib/active_record/tasks/redshift_8_0_tasks.rb
134
+ - lib/active_record/tasks/redshift_tasks.rb
135
+ - lib/activerecord-redshift-adapter.rb
136
+ homepage: https://github.com/januszm/activerecord-redshift-adapter
106
137
  licenses:
107
- - New BSD License
138
+ - MIT
108
139
  metadata: {}
109
- post_install_message:
140
+ post_install_message:
110
141
  rdoc_options: []
111
142
  require_paths:
112
143
  - lib
113
144
  required_ruby_version: !ruby/object:Gem::Requirement
114
145
  requirements:
115
- - - ! '>='
146
+ - - ">="
116
147
  - !ruby/object:Gem::Version
117
- version: '0'
148
+ version: '3.0'
118
149
  required_rubygems_version: !ruby/object:Gem::Requirement
119
150
  requirements:
120
- - - ! '>='
151
+ - - ">="
121
152
  - !ruby/object:Gem::Version
122
153
  version: '0'
123
154
  requirements: []
124
- rubyforge_project:
125
- rubygems_version: 2.2.2
126
- signing_key:
155
+ rubygems_version: 3.5.22
156
+ signing_key:
127
157
  specification_version: 4
128
- summary: Rails 3 database adapter support for AWS RedShift.
129
- test_files:
130
- - spec/active_record/base_spec.rb
131
- - spec/active_record/connection_adapters/redshift_adapter_spec.rb
132
- - spec/dummy/config/database.example.yml
133
- - spec/spec_helper.rb
158
+ summary: Amazon Redshift adapter for ActiveRecord
159
+ test_files: []
data/.gitignore DELETED
@@ -1,26 +0,0 @@
1
- # See http://help.github.com/ignore-files/ for more about ignoring files.
2
- #
3
- # If you find yourself ignoring temporary files generated by your text editor
4
- # or operating system, you probably want to add a global ignore instead:
5
- # git config --global core.excludesfile ~/.gitignore_global
6
-
7
- # Ignore bundler config
8
- /.bundle
9
-
10
- # Ignore the default SQLite database.
11
- /db/*.sqlite3
12
-
13
- # Ignore all logfiles and tempfiles.
14
- /log/*.log
15
- /tmp
16
- .idea/*
17
- database.yml
18
- /log/*.pid
19
- spec/dummy/db/*.sqlite3
20
- spec/dummy/log/*.log
21
- spec/dummy/tmp/
22
- spec/dummy/.sass-cache
23
- spec/dummy/config/database.yml
24
- spec/dummy/db/schema.rb
25
-
26
- Gemfile.lock
data/Gemfile DELETED
@@ -1,14 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Declare your gem's dependencies in partitioned.gemspec.
4
- # Bundler will treat runtime dependencies like base dependencies, and
5
- # development dependencies will be added by default to the :development group.
6
- gemspec
7
-
8
- # Declare any dependencies that are still in development here instead of in
9
- # your gemspec. These might include edge Rails or gems from your path or
10
- # Git. Remember to move these dependencies to your gemspec before releasing
11
- # your gem to rubygems.org.
12
-
13
- # To use debugger
14
- # gem 'ruby-debug'
data/Rakefile DELETED
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env rake
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
7
-
8
- task :default => :spec
9
-
10
- begin
11
- require 'rdoc/task'
12
- rescue LoadError
13
- require 'rdoc/rdoc'
14
- require 'rake/rdoctask'
15
- RDoc::Task = Rake::RDocTask
16
- end
17
-
18
- RDoc::Task.new(:rdoc) do |rdoc|
19
- rdoc.rdoc_dir = 'rdoc'
20
- rdoc.title = 'activerecord-redshift-adapter'
21
- rdoc.options << '--line-numbers'
22
- rdoc.rdoc_files.include('README')
23
- rdoc.rdoc_files.include('lib/**/*.rb')
24
- end
25
-
26
- Bundler::GemHelper.install_tasks
@@ -1,24 +0,0 @@
1
- $LOAD_PATH.push File.expand_path("../lib", __FILE__)
2
-
3
- # Maintain your gem's version:
4
- require "activerecord_redshift_adapter/version"
5
-
6
- Gem::Specification.new do |s|
7
- s.name = 'activerecord-redshift-adapter'
8
- s.version = ActiverecordRedshiftAdapter::VERSION
9
- s.license = 'New BSD License'
10
- s.date = '2014-03-30'
11
- s.summary = "Rails 3 database adapter support for AWS RedShift."
12
- s.description = "This gem provides the Rails 3 with database adapter for AWS RedShift."
13
- s.authors = ["Keith Gabryelski"]
14
- s.email = 'keith@fiksu.com'
15
- s.files = `git ls-files`.split("\n")
16
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.require_path = 'lib'
18
- s.homepage = 'http://github.com/fiksu/activerecord-redshift-adapter'
19
- s.add_dependency "pg"
20
- s.add_dependency "activerecord", '>= 3.0.0'
21
- s.add_dependency "activesupport", '>= 3.0.0'
22
- s.add_dependency "arel", '>= 3.0.0'
23
- s.add_development_dependency 'rspec'
24
- end
@@ -1,230 +0,0 @@
1
- module ActiverecordRedshift
2
- class TableManager
3
- attr_reader :default_options
4
-
5
- DEFAULT_OPTIONS = { :exemplar_table_name => nil, :add_identity => false, :temporary => true}
6
-
7
- def initialize(connection, default_options = {})
8
- @connection = connection
9
- table_name_options = {}
10
- if default_options[:partitioned_model]
11
- model = default_options[:partitioned_model]
12
- default_options[:exemplar_table_name] = model.table_name
13
- default_options[:schema_name] = model.configurator.schema_name
14
- end
15
-
16
- if default_options[:table_name].blank?
17
- connection_pid = @connection.execute("select pg_backend_pid() as pid").first['pid'].to_i
18
- table_name_options[:table_name] = "temporary_events_#{connection_pid}"
19
- end
20
- @default_options = DEFAULT_OPTIONS.merge(table_name_options).merge(default_options)
21
- end
22
-
23
- def partitioned_model
24
- return @default_options[:partitioned_model]
25
- end
26
-
27
- def schema_name
28
- return @default_options[:schema_name]
29
- end
30
-
31
- def exemplar_table_name
32
- return @default_options[:exemplar_table_name]
33
- end
34
-
35
- def add_identity
36
- return @default_options[:add_identity]
37
- end
38
-
39
- def temporary
40
- return @default_options[:temporary]
41
- end
42
-
43
- def base_table_name
44
- return @default_options[:table_name]
45
- end
46
-
47
- def table_name
48
- if schema_name.blank?
49
- return base_table_name
50
- end
51
- return "#{schema_name}.#{base_table_name}"
52
- end
53
-
54
- def drop_table
55
- @connection.execute("drop table #{table_name}")
56
- end
57
-
58
- def duplicate_table(options = {})
59
- current_options = @default_options.merge(options)
60
- target_table_name = current_options[:table_name]
61
- raise "target_table_name not set" if target_table_name.blank?
62
- exemplar_table_name = current_options[:exemplar_table_name]
63
- raise "exemplar_table_name not set" if exemplar_table_name.blank?
64
- table_name_elements = exemplar_table_name.split('.');
65
- if table_name_elements.length == 1
66
- table_name_elements.unshift("public")
67
- end
68
- schema_name = table_name_elements[0]
69
- parent_table_name = table_name_elements[1]
70
-
71
- # first find the diststyle
72
- ## namespace first
73
- sql = "select oid from pg_namespace where nspname = '#{schema_name}' limit 1"
74
- schema_oid = @connection.execute(sql).first['oid'].to_i
75
-
76
- ## now the diststyle 0 = even, 1 = some column
77
- sql = "select oid,reldiststyle from pg_class where relnamespace = #{schema_oid} and relname = '#{parent_table_name}' limit 1"
78
- pg_class_row = @connection.execute(sql).first
79
- reldiststyle = pg_class_row['reldiststyle'].to_i
80
- even_diststyle = (reldiststyle == 0)
81
- table_oid = pg_class_row['oid'].to_i
82
-
83
- ## get unique and primary key constraints (pg_constraints)
84
- sql = "select contype,conkey from pg_constraint where connamespace = #{schema_oid} and conrelid = #{table_oid}"
85
- primary_key = nil
86
- uniques = []
87
- @connection.execute(sql).each do |row|
88
- if row['contype'] == 'p'
89
- # primary key
90
- primary_key = row['conkey'][1..-2].split(',')
91
- elsif row['contype'] == 'u'
92
- # unique
93
- uniques << row['conkey'][1..-2].split(',')
94
- end
95
- end
96
-
97
- attnums = uniques.clone
98
- unless primary_key.blank?
99
- attnums << primary_key
100
- end
101
- attnums = attnums.flatten.uniq
102
-
103
- column_names = {}
104
- if attnums.length > 0
105
- sql = "select attname,attnum from pg_attribute where attrelid = #{table_oid} and attnum in (#{attnums.join(',')})"
106
- @connection.execute(sql).each do |row|
107
- column_names[row['attnum']] = row['attname']
108
- end
109
- end
110
-
111
- column_defaults = {}
112
- sql = "select a.attname,d.adsrc from pg_attribute as a,pg_attrdef as d where a.attrelid = d.adrelid and d.adnum = a.attnum and a.attrelid = #{table_oid}"
113
- @connection.execute(sql).each do |row|
114
- column_defaults[row['attname']] = row['adsrc']
115
- end
116
-
117
- with_search_path([schema_name]) do
118
- # select * from pg_table_def where tablename = 'bids' and schemaname = 'public';
119
- ## column, type, encoding, distkey, sortkey, not null
120
- sortkeys = []
121
- sql_columns = []
122
-
123
- if current_options[:add_identity]
124
- sql_columns << "_identity bigint identity"
125
- end
126
-
127
- sql = "select * from pg_table_def where tablename = '#{parent_table_name}' and schemaname = '#{schema_name}'"
128
- sql_column_rows = @connection.execute(sql)
129
- sql_column_rows.each do |row|
130
- column_info = []
131
- column_name = row['column']
132
- column_info << column_name
133
- column_info << row['type']
134
- if row['notnull'] == "t"
135
- column_info << "not null"
136
- end
137
- if row['distkey'] == "t"
138
- column_info << "distkey"
139
- end
140
- if row['encoding'] != 'none'
141
- column_info << "encode #{row['encoding']}"
142
- end
143
- if row['sortkey'] != "0"
144
- sortkeys[row['sortkey'].to_i - 1] = column_name
145
- end
146
- unless column_defaults[column_name].blank?
147
- column_info << "default #{column_defaults[column_name]}"
148
- end
149
-
150
- sql_columns << column_info.join(" ")
151
- end
152
-
153
- unless primary_key.blank?
154
- sql_columns << "primary key (#{primary_key.map{|pk| column_names[pk]}.join(',')})"
155
- end
156
-
157
- uniques.each do |unique|
158
- sql_columns << "unique (#{unique.map{|uk| column_names[uk]}.join(',')})"
159
- end
160
-
161
- if sortkeys.blank?
162
- sql_sortkeys = ""
163
- else
164
- sql_sortkeys = " sortkey (#{sortkeys.join(',')})"
165
- end
166
- sql = <<-SQL
167
- create #{"temporary " if current_options[:temporary]}table #{table_name}
168
- (
169
- #{sql_columns.join(', ')}
170
- ) #{"diststyle even " if even_diststyle}#{sql_sortkeys}
171
- SQL
172
- @connection.execute(sql)
173
- end
174
- end
175
-
176
- def table_def(table_name)
177
- table_parts = table_name.split('.')
178
- if table_parts.length == 1
179
- name = table_parts.first
180
- search_path = ["public"]
181
- else
182
- name = table_parts.last
183
- search_path = [table_parts.first]
184
- end
185
-
186
- with_search_path(search_path) do
187
- return @connection.execute("select * from pg_table_def where tablename = '#{name}'").to_a
188
- end
189
- end
190
-
191
- # search_path = array
192
- # modes: :prefix, :suffix, :replace
193
- def with_search_path(search_path, mode = :replace, &block)
194
- unless search_path.is_a? Array
195
- raise "search_path must be an Array"
196
- end
197
-
198
- old_search_path = get_search_path
199
- if mode == :prefix
200
- new_search_path = search_path + old_search_path
201
- elsif mode == :suffix
202
- new_search_path = old_search_path + search_path
203
- elsif mode == :replace
204
- new_search_path = search_path
205
- else
206
- raise "mode must be :prefix, :suffix, :replace"
207
- end
208
-
209
- set_search_path(new_search_path)
210
- begin
211
- yield
212
- ensure
213
- set_search_path(old_search_path)
214
- end
215
- end
216
-
217
- def get_search_path
218
- return @connection.execute("show search_path").to_a.first["search_path"].split(',').map{|p| p.delete('" ')}
219
- end
220
-
221
- def set_search_path(search_path)
222
- unless search_path.is_a? Array
223
- raise "search_path must be an Array"
224
- end
225
- quoted_search_path = search_path.map{|sp| "'#{sp}'"}.join(',')
226
- @connection.execute("set search_path = #{quoted_search_path}")
227
- end
228
-
229
- end
230
- end
@@ -1,4 +0,0 @@
1
- module ActiverecordRedshiftAdapter
2
- # the current version of this gem
3
- VERSION = "0.9.12"
4
- end
@@ -1,4 +0,0 @@
1
- require 'activerecord_redshift_adapter/version'
2
- require 'activerecord_redshift/table_manager'
3
- require 'monkeypatch_activerecord'
4
- require 'monkeypatch_arel'