internal/docsite/migrations.go
internal/docsite · 278 lines · 16 declarations · source
Declarations
type migrationSet
type migrationSet struct {
key, label, dir, applies string
scripts []migrate.Script
}
func renderMigrations
func renderMigrations(opts Options) (rendered, error)
func migrationBody
func migrationBody(set migrationSet, s migrate.Script, title, header string, opts Options) string
func sentence
func sentence(name string) string
sentence turns a file name back into the sentence it was named with.
var ruleLine, bannerLine
var (
ruleLine = regexp.MustCompile(`^[\s═─=\-#]*$`)
bannerLine = regexp.MustCompile(`^[═─]{2,}\s*(.+?)\s*[═─]*$`)
)
func commentHeader
func commentHeader(source, marker string) string
commentHeader renders the comment block a file opens with. The headers here are prose with a house style — banner lines for sections, rules for emphasis, capitals for stress — so banners become headings, rules disappear, and more deeply indented lines keep their layout.
var blankRun
var blankRun = regexp.MustCompile(`\n{3,}`)
func renderComment
func renderComment(lines []string) string
func indentOf
func indentOf(l string) int
func headingCase
func headingCase(s string) string
headingCase lowers a heading written in capitals for emphasis, which reads as shouting in a rendered page, and leaves one written in ordinary case alone.
func plain
func plain(md string) string
plain strips markdown structure, for the one-line summaries in tables.
var statementStart
var statementStart = regexp.MustCompile(`(?i)^\s*(CREATE|ALTER|DROP|GRANT|REVOKE|COMMENT\s+ON|INSERT\s+INTO|UPDATE|DELETE\s+FROM|TRUNCATE)\b`)
func statements
func statements(sql string) []string
statements lists what a migration does, one line per statement, reading only top-level SQL: the bodies of functions are the function's business and would otherwise read as migration steps.
func stripComments
func stripComments(sql string) string
var dollarTag
var dollarTag = regexp.MustCompile(`\$[A-Za-z_]*\$`)
func stripBodies
func stripBodies(sql string) string
stripBodies removes dollar-quoted text, closing each on the tag that opened it.