{"record":{"id":"6d55ab2b03aa92fc","repo":"ory/hydra","slug":"problem-checking-for-migration-version-s","errorCode":null,"errorMessage":"problem checking for migration version %s","messagePattern":"problem checking for migration version (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"oryx/popx/migrator.go","lineNumber":202,"sourceCode":"\t}\n\n\t// Keep applied across whole-run retry attempts. Every migration counted here\n\t// has already committed its schema_migration row, so it remains part of this\n\t// UpTo call's step budget even when a later migration retries.\n\terr = mb.exec(ctx, func() error {\n\t\tmtn := sanitizedMigrationTableName(c)\n\t\tmfs := mb.migrationsUp.sortAndFilter(mb.c.Dialect.Name(), mb.migrationFallbacks()...)\n\t\tfor _, mi := range mfs {\n\t\t\tl := mb.l.WithField(\"version\", mi.Version).WithField(\"migration_name\", mi.Name).WithField(\"migration_file\", mi.Path)\n\n\t\t\tappliedMigrations := make([]string, 0, 2)\n\t\t\tlegacyVersion := mi.Version\n\t\t\tif len(legacyVersion) > 14 {\n\t\t\t\tlegacyVersion = legacyVersion[:14]\n\t\t\t}\n\t\t\terr := c.RawQuery(fmt.Sprintf(\"SELECT version FROM %s WHERE version IN (?, ?)\", mtn), mi.Version, legacyVersion).All(&appliedMigrations)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrapf(err, \"problem checking for migration version %s\", mi.Version)\n\t\t\t}\n\n\t\t\tif slices.Contains(appliedMigrations, mi.Version) {\n\t\t\t\tl.Debug(\"Migration has already been applied, skipping.\")\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif slices.Contains(appliedMigrations, legacyVersion) {\n\t\t\t\tl.WithField(\"legacy_version\", legacyVersion).WithField(\"migration_table\", mtn).Debug(\"Migration has already been applied in a legacy migration run. Updating version in migration table.\")\n\t\t\t\tif err := mb.isolatedTransaction(ctx, \"init-migrate\", func(conn *pop.Connection) error {\n\t\t\t\t\t// We do not want to remove the legacy migration version or subsequent migrations might be applied twice.\n\t\t\t\t\t//\n\t\t\t\t\t// Do not activate the following - it is just for reference.\n\t\t\t\t\t//\n\t\t\t\t\t// if _, err := tx.Store.Exec(fmt.Sprintf(\"DELETE FROM %s WHERE version = ?\", mtn), legacyVersion); err != nil {\n\t\t\t\t\t//\treturn errors.Wrapf(err, \"problem removing legacy version %s\", mi.Version)\n\t\t\t\t\t// }\n","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/popx/migrator.go#L184-L220","documentation":"Before applying a migration, UpTo checks the schema_migrations table for the version (and its legacy 14-char-truncated variant). If the raw query fails, the error is wrapped with 'problem checking for migration version %s', naming the migration version being checked.","triggerScenarios":"SELECT version FROM <schema_migrations> fails — table missing (fresh DB where creation failed), wrong dialect SQL, permissions denied, or connection error during the query.","commonSituations":"Migrations table dropped manually; running against a database user lacking SELECT privileges; DB connection dropped mid-run; schema_migrations table created by a different tool with a different schema.","solutions":["Verify the schema_migrations table exists (run the library's migration init/create command)","Check the DB user has SELECT privileges on the migrations table","Inspect the wrapped cause for connection/dialect-specific errors","Recreate a corrupted migrations table from the library's expected schema"],"exampleFix":"// before\npsql -U app -d db -c \"SELECT * FROM schema_migrations\" -- permission denied\n// after\nGRANT SELECT ON schema_migrations TO app;","handlingStrategy":"try-catch","validationCode":"// Verify migrations table exists and is readable before running migrations\nexists, err := tableExists(db, \"schema_migrations\")\nif err != nil { return err }\nif !exists {\n  return errors.New(\"schema_migrations table missing; run migration init first\")\n}","typeGuard":null,"tryCatchPattern":"if err := mb.UpTo(ctx, -1); err != nil {\n  if strings.Contains(err.Error(), \"problem checking for migration version\") {\n    // inspect wrapped cause; possibly re-init migrations table\n    log.Printf(\"version check failed: %v\", errors.Unwrap(err))\n  }\n  return err\n}","preventionTips":["Never drop or hand-edit the schema_migrations table","Grant the app DB user SELECT on the migrations table","Use the library's init/create commands to set up migration tracking","Check DB connectivity with PingContext before running migrations"],"tags":["migrations","sql","go","database"],"backgroundTag":"migration-version-check-failed","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"}