File tree Expand file tree Collapse file tree 4 files changed +11
-6
lines changed
active_record/connection_adapters/clickhouse
fixtures/migrations/plain_function_creation Expand file tree Collapse file tree 4 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ def materialized_views(name = nil)
7979 end
8080
8181 def functions
82- result = do_system_execute ( "SELECT name FROM system.functions WHERE origin = 'SQLUserDefined'" )
82+ result = do_system_execute ( "SELECT name FROM system.functions WHERE origin = 'SQLUserDefined' ORDER BY name " )
8383 return [ ] if result . nil?
8484 result [ 'data' ] . flatten
8585 end
Original file line number Diff line number Diff line change @@ -47,12 +47,12 @@ def structure_dump(*args)
4747 tables . sort_by! { |table | table . match ( /^CREATE\s +(MATERIALIZED\s +)?VIEW/ ) ? 1 : 0 }
4848
4949 # get all functions
50- functions = connection . execute ( "SELECT create_query FROM system.functions WHERE origin = 'SQLUserDefined'" ) [ 'data' ] . flatten
50+ functions = connection . execute ( "SELECT create_query FROM system.functions WHERE origin = 'SQLUserDefined' ORDER BY name " ) [ 'data' ] . flatten
5151
5252 # put to file
5353 File . open ( args . first , 'w:utf-8' ) do |file |
5454 functions . each do |function |
55- file . puts function + ";\n \n "
55+ file . puts function . gsub ( '\\n' , " \n " ) + ";\n \n "
5656 end
5757
5858 tables . each do |table |
Original file line number Diff line number Diff line change 33class CreateSomeFunction < ActiveRecord ::Migration [ 7.1 ]
44 def up
55 sql = <<~SQL
6- CREATE FUNCTION some_fun AS (x,y) -> x + y
6+ CREATE FUNCTION multFun AS (x,y) -> x * y
7+ SQL
8+ do_execute ( sql , format : nil )
9+
10+ sql = <<~SQL
11+ CREATE FUNCTION addFun AS (x,y) -> x + y
712 SQL
813 do_execute ( sql , format : nil )
914 end
Original file line number Diff line number Diff line change 381381 it 'creates a function' do
382382 subject
383383
384- expect ( ActiveRecord ::Base . connection . functions ) . to match_array ( [ 'some_fun ' ] )
384+ expect ( ActiveRecord ::Base . connection . functions ) . to match_array ( [ 'addFun' , 'multFun '] )
385385 end
386386 end
387387
392392
393393 subject
394394
395- expect ( ActiveRecord ::Base . connection . functions ) . to match_array ( [ 'some_fun ' , 'forced_fun ' ] )
395+ expect ( ActiveRecord ::Base . connection . functions ) . to match_array ( [ 'forced_fun ' , 'some_fun ' ] )
396396 expect ( ActiveRecord ::Base . connection . show_create_function ( 'forced_fun' ) . chomp ) . to eq ( 'CREATE FUNCTION forced_fun AS (x, y) -> (x + y)' )
397397 end
398398 end
You can’t perform that action at this time.
0 commit comments