Skip to content

Commit

Permalink
Merge pull request #4 from oelmekki/default_params
Browse files Browse the repository at this point in the history
FIX functions default parameters
  • Loading branch information
oelmekki authored Dec 31, 2016
2 parents 3898193 + c3bebe5 commit f714bb7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions function.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"fmt"
"regexp"
"strings"
)

/*
Expand Down Expand Up @@ -84,6 +85,9 @@ func ( function *Function ) Parse() ( err error ) {
if err != nil { return err }
}

err = function.removeDefaultFromSignature()
if err != nil { return }

return
}

Expand Down Expand Up @@ -125,3 +129,28 @@ func ( function *Function ) previousSignature() ( signature string, exists bool,

return
}


/*
* `DROP FUNCTION` raises error if the signature contains `DEFAULT` values for
* parameters, so we must remove them.
*/
func ( function *Function ) removeDefaultFromSignature() ( err error ) {
anyDefault, err := regexp.MatchString( "(?i)DEFAULT", function.Signature )
if err != nil { return }

if anyDefault {
arguments := strings.Split( function.Signature, "," )
newArgs := make( []string, 0 )

for _, arg := range arguments {
arg = strings.Replace( arg, " DEFAULT ", " default ", -1 )
newArg := strings.Split( arg, " default " )[0]
newArgs = append( newArgs, newArg )
}

function.Signature = strings.Join( newArgs, "," )
}

return
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func CheckSanity() {
*/
func Usage() {
usage := `
PgRebase-1.1.0
PgRebase-1.1.1+
USAGE:
DATABASE_URL=url pgrebase [-w] <sql_directory>
Expand Down

0 comments on commit f714bb7

Please sign in to comment.