chore: fix linter

pull/3844/head
Steven 12 months ago
parent 525223c261
commit 70837f88cb

@ -18,12 +18,12 @@ import (
) )
const ( const (
// MIGRATE_FILE_NAME_SPLIT is the split character between the patch version and the description in the migration file name. // MigrateFileNameSplit is the split character between the patch version and the description in the migration file name.
// For example, "1__create_table.sql". // For example, "1__create_table.sql".
MIGRATE_FILE_NAME_SPLIT = "__" MigrateFileNameSplit = "__"
// LATEST_SCHEMA_FILE_NAME is the name of the latest schema file. // LatestSchemaFileName is the name of the latest schema file.
// This file is used to apply the latest schema when no migration history is found. // This file is used to apply the latest schema when no migration history is found.
LATEST_SCHEMA_FILE_NAME = "LATEST__SCHEMA.sql" LatestSchemaFileName = "latest_schema.sql"
) )
//go:embed migration //go:embed migration
@ -118,7 +118,7 @@ func (s *Store) preMigrate(ctx context.Context) error {
if err != nil { if err != nil {
slog.Warn("failed to find migration history in pre-migrate", slog.String("error", err.Error())) slog.Warn("failed to find migration history in pre-migrate", slog.String("error", err.Error()))
} }
filePath := s.getMigrationBasePath() + LATEST_SCHEMA_FILE_NAME filePath := s.getMigrationBasePath() + LatestSchemaFileName
bytes, err := migrationFS.ReadFile(filePath) bytes, err := migrationFS.ReadFile(filePath)
if err != nil { if err != nil {
return errors.Errorf("failed to read latest schema file: %s", err) return errors.Errorf("failed to read latest schema file: %s", err)
@ -206,14 +206,13 @@ func (s *Store) GetCurrentSchemaVersion() (string, error) {
sort.Strings(filePaths) sort.Strings(filePaths)
if len(filePaths) == 0 { if len(filePaths) == 0 {
return fmt.Sprintf("%s.0", minorVersion), nil return fmt.Sprintf("%s.0", minorVersion), nil
} else {
return s.getSchemaVersionOfMigrateScript(filePaths[len(filePaths)-1])
} }
return s.getSchemaVersionOfMigrateScript(filePaths[len(filePaths)-1])
} }
func (s *Store) getSchemaVersionOfMigrateScript(filePath string) (string, error) { func (s *Store) getSchemaVersionOfMigrateScript(filePath string) (string, error) {
// If the file is the latest schema file, return the current schema version. // If the file is the latest schema file, return the current schema version.
if strings.HasSuffix(filePath, LATEST_SCHEMA_FILE_NAME) { if strings.HasSuffix(filePath, LatestSchemaFileName) {
return s.GetCurrentSchemaVersion() return s.GetCurrentSchemaVersion()
} }
@ -223,7 +222,7 @@ func (s *Store) getSchemaVersionOfMigrateScript(filePath string) (string, error)
return "", errors.Errorf("invalid file path: %s", filePath) return "", errors.Errorf("invalid file path: %s", filePath)
} }
minorVersion := elements[len(elements)-2] minorVersion := elements[len(elements)-2]
rawPatchVersion := strings.Split(elements[len(elements)-1], MIGRATE_FILE_NAME_SPLIT)[0] rawPatchVersion := strings.Split(elements[len(elements)-1], MigrateFileNameSplit)[0]
patchVersion, err := strconv.Atoi(rawPatchVersion) patchVersion, err := strconv.Atoi(rawPatchVersion)
if err != nil { if err != nil {
return "", errors.Wrapf(err, "failed to convert patch version to int: %s", rawPatchVersion) return "", errors.Wrapf(err, "failed to convert patch version to int: %s", rawPatchVersion)
@ -232,7 +231,7 @@ func (s *Store) getSchemaVersionOfMigrateScript(filePath string) (string, error)
} }
// execute runs a single SQL statement within a transaction. // execute runs a single SQL statement within a transaction.
func (s *Store) execute(ctx context.Context, tx *sql.Tx, stmt string) error { func (*Store) execute(ctx context.Context, tx *sql.Tx, stmt string) error {
if _, err := tx.ExecContext(ctx, stmt); err != nil { if _, err := tx.ExecContext(ctx, stmt); err != nil {
return errors.Wrap(err, "failed to execute statement") return errors.Wrap(err, "failed to execute statement")
} }

Loading…
Cancel
Save