func SplitSQLStatements(r io.ReadSeeker, direction bool) ([]string, error) {
	_, err := r.Seek(0, 0)
	if err != nil {
		return nil, err
	}
	var buf bytes.Buffer
	scanner := bufio.NewScanner(r)
	upSections := 0
	downSections := 0
	statementEnded := false
	ignoreSemicolons := false
	directionIsActive := false
	stmts := make([]string, 0)
	for scanner.Scan() {
		line := scanner.Text()
		if strings.HasPrefix(line, sqlCmdPrefix) {
			cmd := strings.TrimSpace(line[len(sqlCmdPrefix):])
			switch cmd {
			case "Up":
				directionIsActive = (direction == true)
				upSections++
				break
			case "Down":
				directionIsActive = (direction == false)
				downSections++
				break
			case "StatementBegin":
				if directionIsActive {
					ignoreSemicolons = true
				}
				break
			case "StatementEnd":
				if directionIsActive {
					statementEnded = (ignoreSemicolons == true)
					ignoreSemicolons = false
				}
				break
			}
		}
		if !directionIsActive {
			continue
		}
		if _, err := buf.WriteString(line + "\n"); err != nil {
			return nil, err
		}
		if (!ignoreSemicolons && endsWithSemicolon(line)) || statementEnded {
			statementEnded = false
			stmts = append(stmts, buf.String())
			buf.Reset()
		}
	}
	if err := scanner.Err(); err != nil {
		return nil, err
	}
	if ignoreSemicolons {
		return nil, errors.New("ERROR: saw '-- +migrate StatementBegin' with no matching '-- +migrate StatementEnd'")
	}
	if upSections == 0 && downSections == 0 {
		return nil, errors.New(`ERROR: no Up/Down annotations found, so no statements were executed.
			See https: 
	}
	return stmts, nil
}
Split the given sql script into individual statements.

The base case is to simply split on semicolons, as these
naturally terminate a statement.

However, more complex cases like pl/pgsql can have semicolons
within a statement. For these cases, we provide the explicit annotations
'StatementBegin' and 'StatementEnd' to allow the script to
tell us to ignore semicolons.
package sqlparse
import (
	"bufio"
	"bytes"
	"errors"
	"io"
	"strings"
)
const sqlCmdPrefix = "-- +migrate "
func endsWithSemicolon(line string) bool {
	prev := ""
	scanner := bufio.NewScanner(strings.NewReader(line))
	scanner.Split(bufio.ScanWords)
	for scanner.Scan() {
		word := scanner.Text()
		if strings.HasPrefix(word, "--") {
			break
		}
		prev = word
	}
	return strings.HasSuffix(prev, ";")
}