aboutsummaryrefslogtreecommitdiffstats
path: root/internal/models/migration.go
blob: 74a15363cdcc4c440f2369055dd6356ac2e25c12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package models

import (
	"fmt"
	"strings"
)

type Migration struct {
	Version string
	Message string
	Applied bool
}

func NewMigration(version uint64, message string) *Migration {
	return &Migration{
		Version: fmt.Sprintf("%04d", version),
		Message: message,
		Applied: false,
	}
}

// NormalizedMessage gives back the Message in lowercase,
// leading and trailing whitespace removed, and spaces
// replaced with underscores.
func (m Migration) NormalizedMessage() string {
	message := strings.ToLower(m.Message)
	message = strings.TrimSpace(message)
	message = strings.ReplaceAll(message, " ", "_")
	return message
}

func (m *Migration) Name() string {
	return fmt.Sprintf("%s_%s", m.Version, m.NormalizedMessage())
}