teoljungberg / fx

Versioned database functions and triggers for Rails
MIT License
763 stars 77 forks source link

Why can't drop fuction by name #32

Closed lyb124553153 closed 5 years ago

lyb124553153 commented 5 years ago

here is my_code

pry(main)> Fx.database.functions.map(&:name)
   (2.5ms)            SELECT
              pp.proname AS name,
              pg_get_functiondef(pp.oid) AS definition
          FROM pg_proc pp
          JOIN pg_namespace pn
              ON pn.oid = pp.pronamespace
          LEFT JOIN pg_depend pd
              ON pd.objid = pp.oid AND pd.deptype = 'e'
          WHERE pn.nspname = 'public'
            AND NOT pp.proisagg
            AND pd.objid IS NULL
          ORDER BY pp.oid;
 /*application:Pi*/
=> ["sfunc_for_multi_currency_agg", "ratio", "multi_currency_plus", "trans_to"]
pry(main)> Fx.database.drop_function('trans_to')
   (0.6ms)  DROP FUNCTION trans_to(); /*application:Pi*/
ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR:  function trans_to() does not exist
teoljungberg commented 5 years ago

It's probably the same as #27, your functions trans_to accepts parameters and to drop the function you need to specify the type signature of the parameters with the function name. As you can have two functions both named foo i.e foo(a int) and foo(a text).

I'd like to support it, but as for now - I haven't had the need of having this feature. I'd like to implement it though, when I have time to do so, but if someone opens up a PR that resolves it. I'd definitely review it and merge it.