From 801ceebef18dd468e3a13648158554ac1fc962fd Mon Sep 17 00:00:00 2001 From: Manuel Kniep Date: Wed, 10 Jun 2020 14:25:38 +0200 Subject: [PATCH 1/4] ake dumbo great again --- dumbo.gemspec | 6 +++--- lib/dumbo/function.rb | 18 +++++++++++------- spec/dumbo_sample/dumbo_sample--0.0.4.sql | 4 ++-- spec/extension_spec.rb | 2 +- spec/operator_spec.rb | 2 +- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/dumbo.gemspec b/dumbo.gemspec index b41196c..1438edc 100644 --- a/dumbo.gemspec +++ b/dumbo.gemspec @@ -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 diff --git a/lib/dumbo/function.rb b/lib/dumbo/function.rb index 5543e26..0f22f2a 100644 --- a/lib/dumbo/function.rb +++ b/lib/dumbo/function.rb @@ -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 + 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' @@ -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 diff --git a/spec/dumbo_sample/dumbo_sample--0.0.4.sql b/spec/dumbo_sample/dumbo_sample--0.0.4.sql index a7c1496..249d0a3 100644 --- a/spec/dumbo_sample/dumbo_sample--0.0.4.sql +++ b/spec/dumbo_sample/dumbo_sample--0.0.4.sql @@ -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, diff --git a/spec/extension_spec.rb b/spec/extension_spec.rb index 1801162..04ff9a1 100644 --- a/spec/extension_spec.rb +++ b/spec/extension_spec.rb @@ -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 diff --git a/spec/operator_spec.rb b/spec/operator_spec.rb index b454306..ccaa824 100644 --- a/spec/operator_spec.rb +++ b/spec/operator_spec.rb @@ -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 From 389270f4e673cf989bdba0f22b2826523f1f3cce Mon Sep 17 00:00:00 2001 From: Manuel Kniep Date: Wed, 10 Jun 2020 16:13:45 +0200 Subject: [PATCH 2/4] more wip --- lib/dumbo/test/matchers.rb | 2 +- lib/dumbo/test/silence_unknown_oid.rb | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/dumbo/test/matchers.rb b/lib/dumbo/test/matchers.rb index 5557d0d..8693696 100644 --- a/lib/dumbo/test/matchers.rb +++ b/lib/dumbo/test/matchers.rb @@ -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 diff --git a/lib/dumbo/test/silence_unknown_oid.rb b/lib/dumbo/test/silence_unknown_oid.rb index 44d509a..2c3debe 100644 --- a/lib/dumbo/test/silence_unknown_oid.rb +++ b/lib/dumbo/test/silence_unknown_oid.rb @@ -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 From 874263c5897618591e1906520115c01feabaaf8c Mon Sep 17 00:00:00 2001 From: Manuel Kniep Date: Wed, 10 Jun 2020 17:09:50 +0200 Subject: [PATCH 3/4] only delete testfile for which there are spec files --- lib/dumbo/test/regression_helper.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/dumbo/test/regression_helper.rb b/lib/dumbo/test/regression_helper.rb index 8876cc9..ee507a7 100644 --- a/lib/dumbo/test/regression_helper.rb +++ b/lib/dumbo/test/regression_helper.rb @@ -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] From c0e3e25e6c39dde05cb26f8ce5fb7d2106d7e9b7 Mon Sep 17 00:00:00 2001 From: Manuel Kniep Date: Thu, 11 Jun 2020 18:30:53 +0200 Subject: [PATCH 4/4] explicitly sort dependencies --- lib/dumbo/dependency_resolver.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/dumbo/dependency_resolver.rb b/lib/dumbo/dependency_resolver.rb index 123afe1..f93a847 100644 --- a/lib/dumbo/dependency_resolver.rb +++ b/lib/dumbo/dependency_resolver.rb @@ -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