Skip to main content

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
}

source

func renderMigrations

func renderMigrations(opts Options) (rendered, error)

source

func migrationBody

func migrationBody(set migrationSet, s migrate.Script, title, header string, opts Options) string

source

func sentence

func sentence(name string) string

sentence turns a file name back into the sentence it was named with.

source

var ruleLine, bannerLine

var (
ruleLine = regexp.MustCompile(`^[\s═─=\-#]*$`)
bannerLine = regexp.MustCompile(`^[═─]{2,}\s*(.+?)\s*[═─]*$`)
)

source

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.

source

var blankRun

var blankRun = regexp.MustCompile(`\n{3,}`)

source

func renderComment

func renderComment(lines []string) string

source

func indentOf

func indentOf(l string) int

source

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.

source

func plain

func plain(md string) string

plain strips markdown structure, for the one-line summaries in tables.

source

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`)

source

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.

source

func stripComments

func stripComments(sql string) string

source

var dollarTag

var dollarTag = regexp.MustCompile(`\$[A-Za-z_]*\$`)

source

func stripBodies

func stripBodies(sql string) string

stripBodies removes dollar-quoted text, closing each on the tag that opened it.

source