Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pg12 #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dumbo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ Gem::Specification.new do |spec|

spec.add_dependency "rake"
spec.add_dependency 'erubis'
spec.add_dependency 'rspec', '~> 3.0.0'
spec.add_dependency 'rspec'
spec.add_dependency 'activerecord'
spec.add_dependency 'pg', '> 0.17'
spec.add_dependency 'pg'

spec.add_dependency 'thor'
spec.add_dependency 'activesupport'

spec.add_dependency "bundler", "~> 1.5"
spec.add_dependency "bundler"
end
3 changes: 2 additions & 1 deletion lib/dumbo/dependency_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def initialize(file_list)
end

def resolve
list = dependency_list.sort { |a, b| a.last.size <=> b.last.size }
# sort by dependency size and name
list = dependency_list.sort_by {|a| [ a.last.size, a.first ]}
resolve_list(list)
end

Expand Down
18 changes: 11 additions & 7 deletions lib/dumbo/function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ def load_attributes
pg_catalog.pg_get_function_result(p.oid) as result_type,
pg_catalog.pg_get_function_arguments(p.oid) as args,
pg_catalog.pg_get_function_identity_arguments(p.oid) as arg_types,
CASE
WHEN p.proisagg THEN 'agg'
WHEN p.proiswindow THEN 'window'
WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN 'trigger'
ELSE 'normal'
END as "type",
CASE p.prokind
Copy link

@alexeyklyukin alexeyklyukin Jun 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PG 11 made it a pain by renaming pro kind, since pg10 is still out there and supported until 2022 we might want to retain compatibility. I'd execute different SQLs depending on whether current_setting('server_version_num')::integer > 110000

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should focus for now making dumbo usable for adjust.
Making it usable for a broader audience could be the next step.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

WHEN 'a' THEN 'agg'
WHEN 'w' THEN 'window'
WHEN 'p' THEN 'proc'
ELSE
CASE WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype
THEN 'trigger'
ELSE 'normal'
END
END as "type",
CASE
WHEN p.provolatile = 'i' THEN 'immutable'
WHEN p.provolatile = 's' THEN 'stable'
Expand All @@ -60,7 +64,7 @@ def load_attributes
l.lanname as language,
p.prosrc as "source",
pg_catalog.obj_description(p.oid, 'pg_proc') as description,
CASE WHEN p.proisagg THEN 'agg_dummy' ELSE pg_get_functiondef(p.oid) END as definition
CASE WHEN p.prokind = 'a' THEN 'agg_dummy' ELSE pg_get_functiondef(p.oid) END as definition

FROM pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang
Expand Down
2 changes: 1 addition & 1 deletion lib/dumbo/test/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def throw_error(expected)
end

def flat_expected(expected)
expected = stringify_array(expected)
#expected = stringify_array(expected)
expected.size == 1 ? expected.first : expected
end

Expand Down
5 changes: 1 addition & 4 deletions lib/dumbo/test/regression_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
path = self.class.metadata[:file_path]
test_file = Pathname.new(path).basename.sub_ext('.sql').sub('_spec','_test')
test_path = test_file.realdirpath File.expand_path('test/sql')
FileUtils.rm(test_path, force: true)
FileUtils.touch(test_path)

ActiveRecord::Base.logger = Dumbo::Test::Helper::SqlLogger.new(test_path)
ActiveRecord::Base.logger.level = 0
end

config.before(:suite) do |s|
FileUtils.rm_r Dir.glob('test/sql/*'), force: true
end

config.before(:each) do |example|
ActiveRecord::Base.logger.debug "-- " + example.metadata[:full_description]
ActiveRecord::Base.logger.debug "-- " + example.metadata[:location]
Expand Down
8 changes: 3 additions & 5 deletions lib/dumbo/test/silence_unknown_oid.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
module ActiveRecord
module ConnectionAdapters
class PostgreSQLAdapter
module DatabaseStatements
def warn(msg)
return if msg =~ /^unknown OID/
super
end
def warn(msg)
return if msg =~ /^unknown OID/
super
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/dumbo_sample/dumbo_sample--0.0.4.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
CREATE TYPE elephant_base;

CREATE FUNCTION elephant_in(cstring) RETURNS elephant_base AS
'$libdir/dumbo_sample' LANGUAGE C;
'$libdir/dumbo_sample' LANGUAGE C IMMUTABLE;

CREATE FUNCTION elephant_out(elephant_base) RETURNS cstring AS
'$libdir/dumbo_sample' LANGUAGE C;
'$libdir/dumbo_sample' LANGUAGE C IMMUTABLE;

CREATE TYPE elephant_base (
INPUT = elephant_in,
Expand Down
2 changes: 1 addition & 1 deletion spec/extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

it 'should return extension obj_id' do
expect(extension.obj_id).to match /\d+/
expect(extension.obj_id).to be_kind_of(Integer)
end

it 'should return a list of objects' do
Expand Down
2 changes: 1 addition & 1 deletion spec/operator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
end

it 'should have drop sql' do
expect(operator.drop).to eq 'DROP OPERATOR && (box, box);'
expect(operator.drop).to eq 'DROP OPERATOR IF EXISTS && (box, box);'
end
end