dumbo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +61 -0
  6. data/Rakefile +9 -0
  7. data/bin/dumbo +58 -0
  8. data/config/boot.rb +15 -0
  9. data/config/database.yml +31 -0
  10. data/dumbo.gemspec +31 -0
  11. data/lib/dumbo.rb +21 -0
  12. data/lib/dumbo/aggregate.rb +57 -0
  13. data/lib/dumbo/base_type.rb +71 -0
  14. data/lib/dumbo/cast.rb +49 -0
  15. data/lib/dumbo/composite_type.rb +31 -0
  16. data/lib/dumbo/db_task.rb +57 -0
  17. data/lib/dumbo/dependency_resolver.rb +105 -0
  18. data/lib/dumbo/enum_type.rb +28 -0
  19. data/lib/dumbo/extension.rb +73 -0
  20. data/lib/dumbo/extension_migrator.rb +66 -0
  21. data/lib/dumbo/extension_version.rb +25 -0
  22. data/lib/dumbo/function.rb +101 -0
  23. data/lib/dumbo/operator.rb +74 -0
  24. data/lib/dumbo/pg_object.rb +80 -0
  25. data/lib/dumbo/rake_task.rb +121 -0
  26. data/lib/dumbo/range_type.rb +43 -0
  27. data/lib/dumbo/type.rb +31 -0
  28. data/lib/dumbo/version.rb +3 -0
  29. data/lib/tasks/db.rake +52 -0
  30. data/lib/tasks/dumbo.rake +23 -0
  31. data/spec/Makefile +6 -0
  32. data/spec/aggregate_spec.rb +41 -0
  33. data/spec/cast_spec.rb +20 -0
  34. data/spec/dumbo_sample--0.0.1.sql +5 -0
  35. data/spec/dumbo_sample--0.0.2.sql +5 -0
  36. data/spec/dumbo_sample.control +5 -0
  37. data/spec/extension_migrator_spec.rb +40 -0
  38. data/spec/extension_spec.rb +19 -0
  39. data/spec/operator_spec.rb +42 -0
  40. data/spec/spec_helper.rb +28 -0
  41. data/spec/support/sql_helper.rb +23 -0
  42. data/spec/type_spec.rb +95 -0
  43. data/template/Gemfile +3 -0
  44. data/template/Makefile.erb +6 -0
  45. data/template/Rakefile +15 -0
  46. data/template/config/database.yml.erb +31 -0
  47. data/template/spec/sample_spec.rb.erb +13 -0
  48. data/template/sql/sample.sql +5 -0
  49. metadata +230 -0
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ describe Dumbo::Cast do
3
+ let(:cast) do
4
+ oid = sql("SELECT ca.oid
5
+ FROM pg_cast ca
6
+ JOIN pg_type st ON st.oid=castsource
7
+ JOIN pg_type tt ON tt.oid=casttarget
8
+ WHERE format_type(st.oid,NULL) = 'bigint'
9
+ AND format_type(tt.oid,tt.typtypmod) = 'integer';",'oid').first
10
+ Dumbo::Cast.new(oid)
11
+ end
12
+
13
+ it "should have a sql representation" do
14
+ cast.to_sql.should eq <<-SQL.gsub(/^ {6}/, '')
15
+ CREATE CAST (bigint AS integer)
16
+ WITH FUNCTION int4(bigint)
17
+ AS ASSIGNMENT;
18
+ SQL
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ CREATE FUNCTION foo(integer) RETURNS integer AS $$
2
+ BEGIN
3
+ RETURN $1;
4
+ END
5
+ $$ LANGUAGE 'plpgsql' IMMUTABLE STRICT;
@@ -0,0 +1,5 @@
1
+ CREATE FUNCTION foo(integer) RETURNS integer AS $$
2
+ BEGIN
3
+ RETURN $1 + 10;
4
+ END
5
+ $$ LANGUAGE 'plpgsql' IMMUTABLE STRICT;
@@ -0,0 +1,5 @@
1
+ # dumbo_sample extension
2
+ comment = 'my awesome extension'
3
+ default_version = '0.0.2'
4
+ relocatable = true
5
+ requires = ''
@@ -0,0 +1,40 @@
1
+ describe Dumbo::ExtensionMigrator do
2
+ before(:all) do
3
+ system('cd spec && make clean && make && make install')
4
+ end
5
+ after (:all) do
6
+ system('cd spec && make clean && make uninstall')
7
+ end
8
+
9
+ let(:migrator){Dumbo::ExtensionMigrator.new('dumbo_sample','0.0.1','0.0.2')}
10
+
11
+ it "should provide upgrade sql" do
12
+ migrator.upgrade.should eq <<-SQL.gsub(/^ {4}/, '')
13
+ ----functions----
14
+ CREATE OR REPLACE FUNCTION foo(integer)
15
+ RETURNS integer
16
+ LANGUAGE plpgsql
17
+ IMMUTABLE STRICT
18
+ AS $function$
19
+ BEGIN
20
+ RETURN $1 + 10;
21
+ END
22
+ $function$
23
+ SQL
24
+ end
25
+
26
+ it "should provide downgrade sql" do
27
+ migrator.downgrade.should eq <<-SQL.gsub(/^ {4}/, '')
28
+ ----functions----
29
+ CREATE OR REPLACE FUNCTION foo(integer)
30
+ RETURNS integer
31
+ LANGUAGE plpgsql
32
+ IMMUTABLE STRICT
33
+ AS $function$
34
+ BEGIN
35
+ RETURN $1;
36
+ END
37
+ $function$
38
+ SQL
39
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ describe Dumbo::Extension do
3
+ let(:extension){Dumbo::Extension.new('hstore','1.1')}
4
+ before(:all) do
5
+ Dumbo::Extension.new('hstore','1.1').install
6
+ end
7
+
8
+ it "should return extension obj_id" do
9
+ extension.obj_id.should ~ /\d+/
10
+ end
11
+
12
+ it 'should return a list of objects' do
13
+ extension.objects.size.should eq 86
14
+ end
15
+
16
+ it 'should return a list of types' do
17
+ extension.types.select{|t| t.name == 'hstore'}.should_not be_empty
18
+ end
19
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ describe Dumbo::Operator do
3
+ let(:operator) do
4
+ oid = sql("SELECT oid FROM pg_operator WHERE oprname = '&&' AND format_type(oprleft,NULL) = 'box' AND format_type(oprright,NULL) ='box'",'oid').first
5
+ Dumbo::Operator.new(oid).get
6
+ end
7
+
8
+ it "should have a sql representation" do
9
+ operator.to_sql.should eq <<-SQL.gsub(/^ {4}/, '')
10
+ CREATE OPERATOR && (
11
+ PROCEDURE = box_overlap,
12
+ LEFTARG = box,
13
+ RIGHTARG = box,
14
+ COMMUTATOR = &&,
15
+ RESTRICT = areasel,
16
+ JOIN = areajoinsel
17
+ );
18
+ SQL
19
+ end
20
+
21
+ it 'should have a uniq identfier' do
22
+ operator.identify.should eq ['&&', 'box', 'box']
23
+ end
24
+
25
+ it 'should have upgrade sql' do
26
+ operator.upgrade(nil).should eq <<-SQL.gsub(/^ {4}/, '')
27
+ CREATE OPERATOR && (
28
+ PROCEDURE = box_overlap,
29
+ LEFTARG = box,
30
+ RIGHTARG = box,
31
+ COMMUTATOR = &&,
32
+ RESTRICT = areasel,
33
+ JOIN = areajoinsel
34
+ );
35
+ SQL
36
+ end
37
+
38
+ it 'should have downgrade sql' do
39
+ operator.downgrade(nil).should eq "DROP OPERATOR &&;"
40
+ end
41
+ end
42
+
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'factory_girl'
3
+
4
+ ENV['DUMBO_ENV'] ||= 'test'
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+
7
+ ActiveRecord::Base.logger.level = 0 if ActiveRecord::Base.logger
8
+
9
+ Dir.glob("spec/support/**/*.rb").each { |f| require f }
10
+
11
+ RSpec.configure do |config|
12
+ config.fail_fast = false
13
+ config.order = "random"
14
+ config.treat_symbols_as_metadata_keys_with_true_values = true
15
+ config.include FactoryGirl::Syntax::Methods
16
+ config.filter_run focus: true
17
+ config.run_all_when_everything_filtered = true
18
+
19
+ # wrap test in transactions
20
+ config.around(:each) do |example|
21
+ ActiveRecord::Base.transaction do
22
+ example.run
23
+ raise ActiveRecord::Rollback
24
+ end
25
+ end
26
+
27
+ config.include(SqlHelper)
28
+ end
@@ -0,0 +1,23 @@
1
+ module SqlHelper
2
+ def sql(sql, field = nil)
3
+ result = ActiveRecord::Base.connection.select_all(sql, 'SQL', [])
4
+ hash = result.to_hash
5
+ result = hash.map do |h|
6
+ hash_map = h.map do |k, v|
7
+ type = result.column_types[k]
8
+ casted_value = type.type_cast v
9
+ [k, casted_value]
10
+ end
11
+ Hash[hash_map]
12
+ end
13
+ # binding.pry
14
+ field ? result.map{|h| h[field]} : result
15
+ end
16
+
17
+ def install_extension
18
+ sql "CREATE EXTENSION #{Dumbo::Extension.new.name}"
19
+ end
20
+ end
21
+
22
+
23
+
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+ describe Dumbo::Type do
3
+ describe 'Base Type' do
4
+ let(:type) do
5
+ extension = Dumbo::Extension.new('hstore','1.1')
6
+ extension.install
7
+ extension.types.select{|t| t.name =='hstore'}.first
8
+ end
9
+ it "should have a sql representation" do
10
+ type.to_sql.should eq <<-SQL.gsub(/^ {6}/, '')
11
+ CREATE TYPE hstore(
12
+ INPUT=hstore_in,
13
+ OUTPUT=hstore_out,
14
+ RECEIVE=hstore_recv,
15
+ SEND=hstore_send,
16
+ ANALYZE=-,
17
+ CATEGORY='U',
18
+ DEFAULT='',
19
+ INTERNALLENGTH=-1,
20
+ ALIGNMENT=int,
21
+ STORAGE=EXTENDED
22
+ );
23
+ SQL
24
+ end
25
+
26
+ it 'should have a uniq identfier' do
27
+ type.identify.should eq ['hstore']
28
+ end
29
+ end
30
+
31
+ describe 'Composite Type' do
32
+ let(:type) do
33
+ sql "CREATE TYPE compfoo AS (f1 int, f2 text);"
34
+ oid = sql("SELECT oid FROM pg_type where typname = 'compfoo'",'oid').first
35
+ Dumbo::Type.new(oid).get
36
+ end
37
+
38
+ it "should have a sql representation" do
39
+ type.to_sql.should eq <<-SQL.gsub(/^ {6}/, '')
40
+ CREATE TYPE compfoo AS (
41
+ f1 integer,
42
+ f2 text
43
+ );
44
+ SQL
45
+ end
46
+
47
+ it 'should have a uniq identfier' do
48
+ type.identify.should eq ['compfoo']
49
+ end
50
+ end
51
+
52
+ describe 'Range Type' do
53
+ let(:type) do
54
+ sql "CREATE TYPE float8_range AS RANGE (subtype = float8, subtype_diff = float8mi);"
55
+ oid = sql("SELECT oid FROM pg_type where typname = 'float8_range'",'oid').first
56
+ Dumbo::Type.new(oid).get
57
+ end
58
+
59
+ it "should have a sql representation" do
60
+ type.to_sql.should eq <<-SQL.gsub(/^ {6}/, '')
61
+ CREATE TYPE float8_range AS RANGE (
62
+ SUBTYPE=float8,
63
+ SUBTYPE_OPCLASS=float8_ops,
64
+ SUBTYPE_DIFF=float8mi
65
+ );
66
+ SQL
67
+ end
68
+
69
+ it 'should have a uniq identfier' do
70
+ type.identify.should eq ['float8_range']
71
+ end
72
+ end
73
+
74
+ describe 'Enum Type' do
75
+ let(:type) do
76
+ sql "CREATE TYPE bug_status AS ENUM ('new', 'open', 'closed');"
77
+ oid = sql("SELECT oid FROM pg_type where typname = 'bug_status'",'oid').first
78
+ Dumbo::Type.new(oid).get
79
+ end
80
+
81
+ it "should have a sql representation" do
82
+ type.to_sql.should eq <<-SQL.gsub(/^ {6}/, '')
83
+ CREATE TYPE bug_status AS ENUM (
84
+ 'new',
85
+ 'open',
86
+ 'closed'
87
+ );
88
+ SQL
89
+ end
90
+
91
+ it 'should have a uniq identfier' do
92
+ type.identify.should eq ['bug_status']
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,3 @@
1
+ # Gemfile
2
+ source 'https://rubygems.org'
3
+ gem 'dumbo'
@@ -0,0 +1,6 @@
1
+ #http://blog.pgxn.org/post/4783001135/extension-makefiles pg makefiles
2
+ EXTENSION = <%=ext_name%>
3
+ PG_CONFIG ?= pg_config
4
+ DATA = $(wildcard *--*.sql)
5
+ PGXS := $(shell $(PG_CONFIG) --pgxs)
6
+ include $(PGXS)
@@ -0,0 +1,15 @@
1
+ require 'rake'
2
+ require 'rspec/core/rake_task'
3
+ require 'dumbo/rake_task'
4
+ require 'dumbo/db_task'
5
+ require 'dumbo'
6
+
7
+ load File.expand_path('../config/boot.rb',__FILE__)
8
+
9
+ Dumbo::RakeTask.new(:dumbo)
10
+ Dumbo::DbTask.new(:db)
11
+ RSpec::Core::RakeTask.new(:spec)
12
+
13
+ Dir.glob("lib/tasks/**/*.rake").each { |taskfile| load taskfile }
14
+
15
+ task :default => ['dumbo:all', 'db:test:prepare', :spec]
@@ -0,0 +1,31 @@
1
+ # general postgres settings
2
+ # Connect on a TCP socket. Omitted by default since the client uses a
3
+ # domain socket that doesn't need configuration. Windows does not have
4
+ # domain sockets, so uncomment these lines.
5
+ # host: localhost
6
+ # port: 5432
7
+
8
+ # Schema search path. The server defaults to $user,public
9
+ # schema_search_path: myapp,sharedapp,public
10
+
11
+ # Minimum log levels, in increasing order:
12
+ # debug5, debug4, debug3, debug2, debug1,
13
+ # log, notice, warning, error, fatal, and panic
14
+ # The server defaults to notice.
15
+ # min_messages: warning
16
+
17
+ postgres: &postgres
18
+ adapter: postgresql
19
+ encoding: utf8
20
+ pool: 5
21
+ username: postgres
22
+ password:
23
+ host: localhost
24
+
25
+ development:
26
+ <<: *postgres
27
+ database: <%= ext_name %>_development
28
+
29
+ test:
30
+ <<: *postgres
31
+ database: <%= ext_name %>_test
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe '<%= ext_name %>' do
4
+ before do
5
+ install_extension
6
+ end
7
+
8
+ describe "function foo" do
9
+ it "shoul return the input" do
10
+ sql("SELECT foo(10)", 'foo').first.should eq 10
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ CREATE FUNCTION foo(int) RETURNS int AS $$
2
+ BEGIN
3
+ RETURN $1;
4
+ END
5
+ $$ LANGUAGE 'plpgsql' IMMUTABLE STRICT;
metadata ADDED
@@ -0,0 +1,230 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dumbo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Manuel Kniep
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
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
+ - !ruby/object:Gem::Dependency
28
+ name: erubis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: factory_girl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pg
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.17'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.17'
97
+ - !ruby/object:Gem::Dependency
98
+ name: thor
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.5'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.5'
139
+ description:
140
+ email:
141
+ - m.kniep@web.de
142
+ executables:
143
+ - dumbo
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - Gemfile
149
+ - LICENSE.txt
150
+ - README.md
151
+ - Rakefile
152
+ - bin/dumbo
153
+ - config/boot.rb
154
+ - config/database.yml
155
+ - dumbo.gemspec
156
+ - lib/dumbo.rb
157
+ - lib/dumbo/aggregate.rb
158
+ - lib/dumbo/base_type.rb
159
+ - lib/dumbo/cast.rb
160
+ - lib/dumbo/composite_type.rb
161
+ - lib/dumbo/db_task.rb
162
+ - lib/dumbo/dependency_resolver.rb
163
+ - lib/dumbo/enum_type.rb
164
+ - lib/dumbo/extension.rb
165
+ - lib/dumbo/extension_migrator.rb
166
+ - lib/dumbo/extension_version.rb
167
+ - lib/dumbo/function.rb
168
+ - lib/dumbo/operator.rb
169
+ - lib/dumbo/pg_object.rb
170
+ - lib/dumbo/rake_task.rb
171
+ - lib/dumbo/range_type.rb
172
+ - lib/dumbo/type.rb
173
+ - lib/dumbo/version.rb
174
+ - lib/tasks/db.rake
175
+ - lib/tasks/dumbo.rake
176
+ - spec/Makefile
177
+ - spec/aggregate_spec.rb
178
+ - spec/cast_spec.rb
179
+ - spec/dumbo_sample--0.0.1.sql
180
+ - spec/dumbo_sample--0.0.2.sql
181
+ - spec/dumbo_sample.control
182
+ - spec/extension_migrator_spec.rb
183
+ - spec/extension_spec.rb
184
+ - spec/operator_spec.rb
185
+ - spec/spec_helper.rb
186
+ - spec/support/sql_helper.rb
187
+ - spec/type_spec.rb
188
+ - template/Gemfile
189
+ - template/Makefile.erb
190
+ - template/Rakefile
191
+ - template/config/database.yml.erb
192
+ - template/spec/sample_spec.rb.erb
193
+ - template/sql/sample.sql
194
+ homepage: https://github.com/adjust/dumbo
195
+ licenses:
196
+ - MIT
197
+ metadata: {}
198
+ post_install_message:
199
+ rdoc_options: []
200
+ require_paths:
201
+ - lib
202
+ required_ruby_version: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ required_rubygems_version: !ruby/object:Gem::Requirement
208
+ requirements:
209
+ - - ">="
210
+ - !ruby/object:Gem::Version
211
+ version: '0'
212
+ requirements: []
213
+ rubyforge_project:
214
+ rubygems_version: 2.2.1
215
+ signing_key:
216
+ specification_version: 4
217
+ summary: postgres extension with fun
218
+ test_files:
219
+ - spec/Makefile
220
+ - spec/aggregate_spec.rb
221
+ - spec/cast_spec.rb
222
+ - spec/dumbo_sample--0.0.1.sql
223
+ - spec/dumbo_sample--0.0.2.sql
224
+ - spec/dumbo_sample.control
225
+ - spec/extension_migrator_spec.rb
226
+ - spec/extension_spec.rb
227
+ - spec/operator_spec.rb
228
+ - spec/spec_helper.rb
229
+ - spec/support/sql_helper.rb
230
+ - spec/type_spec.rb