MCPcopy Index your code
hub / github.com/dnote/dnote / validateMigrationFilename

Function validateMigrationFilename

pkg/server/database/migrate.go:36–66  ·  view source on GitHub ↗

validateMigrationFilename checks if filename follows format: NNN-description.sql

(name string)

Source from the content-addressed store, hash-verified

34
35// validateMigrationFilename checks if filename follows format: NNN-description.sql
36func validateMigrationFilename(name string) error {
37 // Check .sql extension
38 if !strings.HasSuffix(name, ".sql") {
39 return errors.Errorf("invalid migration filename: must end with .sql")
40 }
41
42 name = strings.TrimSuffix(name, ".sql")
43 parts := strings.SplitN(name, "-", 2)
44 if len(parts) != 2 {
45 return errors.Errorf("invalid migration filename: must be NNN-description.sql")
46 }
47
48 version, description := parts[0], parts[1]
49
50 // Validate version is 3 digits
51 if len(version) != 3 {
52 return errors.Errorf("invalid migration filename: version must be 3 digits, got %s", version)
53 }
54 for _, c := range version {
55 if c < '0' || c > '9' {
56 return errors.Errorf("invalid migration filename: version must be numeric, got %s", version)
57 }
58 }
59
60 // Validate description is not empty
61 if description == "" {
62 return errors.Errorf("invalid migration filename: description is required")
63 }
64
65 return nil
66}
67
68// Migrate runs the migrations using the embedded migration files
69func Migrate(db *gorm.DB) error {

Callers 1

getMigrationFilesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected