{"record":{"id":"9b6bd6ec2b3de6b0","repo":"ory/hydra","slug":"unknown-migration-direction-q","errorCode":null,"errorMessage":"unknown migration direction %q","messagePattern":"unknown migration direction %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"oryx/popx/migration_box.go","lineNumber":249,"sourceCode":"\t\treturn []string{dbal.DriverPostgreSQL}\n\t}\n\treturn nil\n}\n\n// SelectedMigrations returns a copy of the migrations selected for the\n// connection's dialect and direction. It uses the same exact-match and fallback\n// ranking as Up, Down, and Status so callers can audit the effective migration\n// set without duplicating filename-selection logic.\nfunc (mb *MigrationBox) SelectedMigrations(direction string) (Migrations, error) {\n\tdialect := mb.c.Dialect.Name()\n\tfallbacks := mb.migrationFallbacks()\n\tswitch direction {\n\tcase \"up\":\n\t\treturn slices.Clone(mb.migrationsUp.sortAndFilter(dialect, fallbacks...)), nil\n\tcase \"down\":\n\t\treturn slices.Clone(mb.migrationsDown.sortAndFilter(dialect, fallbacks...)), nil\n\tdefault:\n\t\treturn nil, errors.Errorf(\"unknown migration direction %q\", direction)\n\t}\n}\n\n// noTxDDL reports whether the dialect cannot run DDL inside a transaction, so\n// both migrations and the migration-status table setup must run in autocommit\n// mode. CockroachDB and MySQL auto-commit each DDL statement; YugabyteDB\n// restricts DDL inside transactions. Because there is no surrounding\n// transaction to roll back a partial failure, new YugabyteDB migrations must\n// contain one idempotent statement per file. YugabyteDB also inherits older\n// PostgreSQL migration files that predate this rule; service-level guard tests\n// track that replay risk, and a dedicated .yugabyte. override is required when\n// a new unsafe inherited migration appears.\nfunc (mb *MigrationBox) noTxDDL() bool {\n\tswitch mb.c.Dialect.Name() {\n\tcase dbal.DriverCockroachDB, dbal.DriverMySQL, dbal.DriverYugabyteDB:\n\t\treturn true\n\t}\n\treturn false","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/popx/migration_box.go#L231-L267","documentation":"MigrationBox.SelectedMigrations(direction, dialect, fallbacks...) only accepts \"up\" or \"down\" (oryx/popx/migration_box.go:249). Any other direction string returns this error instead of returning an empty list, catching programmer mistakes early.","triggerScenarios":"Calling SelectedMigrations with a direction other than \"up\" or \"down\" — e.g. \"Up\", \"\", \"apply\", or a variable that was meant to hold a direction but holds something else.","commonSituations":"Passing user/config input straight into SelectedMigrations; case mistakes (\"UP\"); using a status or mode string where a direction string was expected.","solutions":["Pass exactly \"up\" or \"down\" (lowercase) as the direction argument","Normalize/trim input strings before calling SelectedMigrations","Check the calling code for a swapped or mistyped variable"],"exampleFix":"// before\nmfs, err := mb.SelectedMigrations(direction, dialect)\n// after\ndir := strings.ToLower(strings.TrimSpace(direction))\nif dir != \"up\" && dir != \"down\" { return fmt.Errorf(\"invalid direction %q\", direction) }\nmfs, err := mb.SelectedMigrations(dir, dialect)","handlingStrategy":"validation","validationCode":"func validDirection(d string) bool { return d == \"up\" || d == \"down\" }\nif !validDirection(direction) { return fmt.Errorf(\"direction must be up or down, got %q\", direction) }","typeGuard":null,"tryCatchPattern":"mfs, err := mb.SelectedMigrations(direction, dialect)\nif err != nil {\n    if strings.Contains(err.Error(), \"unknown migration direction\") {\n        return fmt.Errorf(\"bad direction %q: use \\\"up\\\" or \\\"down\\\"\", direction)\n    }\n    return err\n}","preventionTips":["Define direction as a typed constant set (\"up\"/\"down\") and validate config input","Never pass raw user/config strings directly as the direction argument","Normalize case and whitespace before calling SelectedMigrations"],"tags":["migrations","api-misuse","go"],"backgroundTag":"invalid-argument","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"}