{"record":{"id":"374faa2423bb95a2","repo":"ory/hydra","slug":"found-a-migration-file-that-does-not-match-the-fil","errorCode":null,"errorMessage":"Found a migration file that does not match the file pattern: filename=%s pattern=%s","messagePattern":"Found a migration file that does not match the file pattern: filename=(.+?) pattern=(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"oryx/popx/migration_box.go","lineNumber":299,"sourceCode":"\t\t\treturn nil\n\t\t}\n\n\t\tif path.Ext(info.Name()) != \".sql\" {\n\t\t\tmb.l.Tracef(\"ignoring non SQL file: %s\", info.Name())\n\t\t\treturn nil\n\t\t}\n\n\t\tdetails, err := parseMigrationFilename(info.Name())\n\t\tif err != nil {\n\t\t\tif errors.Is(err, errUnsupportedMigrationDialect) {\n\t\t\t\tmb.l.Debugf(\"Ignoring migration file %s because its dialect is not supported: %s\", info.Name(), err.Error())\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\treturn errors.WithStack(err)\n\t\t}\n\n\t\tif details == nil {\n\t\t\treturn errors.Errorf(\"Found a migration file that does not match the file pattern: filename=%s pattern=%s\", info.Name(), MigrationFileRegexp)\n\t\t}\n\n\t\tcontent, err := fs.ReadFile(dir, p)\n\t\tif err != nil {\n\t\t\treturn errors.WithStack(err)\n\t\t}\n\n\t\tmf := Migration{\n\t\t\tPath:       p,\n\t\t\tVersion:    details.Version,\n\t\t\tName:       details.Name,\n\t\t\tDBType:     details.DBType,\n\t\t\tDirection:  details.Direction,\n\t\t\tType:       details.Type,\n\t\t\tContent:    string(content),\n\t\t\tAutocommit: details.Autocommit,\n\t\t}\n","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/popx/migration_box.go#L281-L317","documentation":"During findMigrations, every file in the migrations directory/filesystem is parsed with parseMigrationFilename, which returns nil for non-matching names. When a file does not match MigrationFileRegexp (^\\d+_([^.]+)(\\.[a-z0-9]+)?(\\.autocommit)?\\.(up|down)\\.(sql)$), this error (oryx/popx/migration_box.go:299) names the offending filename and the expected pattern so the developer can fix or remove the file.","triggerScenarios":"A file exists in the migrations directory whose name does not satisfy MigrationFileRegexp — missing version number, wrong extension (e.g. .sql.gz, .txt), missing direction, or stray characters in the name.","commonSituations":"Editor backup files (migration.sql~, .DS_Store) or partial downloads in the migrations folder; hand-created migrations missing the version prefix; renaming tools that altered extensions.","solutions":["Rename the offending file to match the pattern: <version>_<name>[.<dialect>][.autocommit].<up|down>.sql","Delete or move non-migration files (backups, READMEs, editor temp files) out of the migrations directory","Verify with the regex MigrationFileRegexp that your filename matches before deploying"],"exampleFix":"// before (no version prefix / wrong extension)\nadd_users_table.txt\n// after\n20240101000000_add_users_table.up.sql","handlingStrategy":"validation","validationCode":"var MigrationFileRegexp = regexp.MustCompile(`^(\\d+)_([^.]+)(\\.[a-z0-9]+)?(\\.autocommit)?\\.(up|down)\\.(sql)$`)\n// fs.WalkDir over your migrations dir; fail fast on non-conforming files before starting the app\nif !MigrationFileRegexp.MatchString(info.Name()) {\n    return fmt.Errorf(\"file %s does not match migration pattern\", info.Name())\n}","typeGuard":null,"tryCatchPattern":"err := mb.Exec(ctx, conn)\nif err != nil {\n    if strings.Contains(err.Error(), \"does not match the file pattern\") {\n        return fmt.Errorf(\"fix or remove the offending file in the migrations directory: %v\", err)\n    }\n    return err\n}","preventionTips":["Keep the migrations directory clean: no editor backups, .DS_Store, READMEs, or partial files","Lint migration filenames in CI before building the embedded FS","Follow the strict naming scheme: <version>_<name>[.<dialect>][.autocommit].<up|down>.sql"],"tags":["migrations","file-naming","database"],"backgroundTag":"invalid-migration-filename","analyzedSha":"4174065ffb052799890f7480f5360a877a67ffc1","analyzedAt":"2026-09-03T14:52:41.581Z","contentChangedAt":"2026-09-03T14:52:41.581Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}