hasura/graphql-engine · error

unable to remove versions from database: %w

Error message

unable to remove versions from database: %w

What it means

Thrown during the config-v2 update script when the migration driver fails to remove already-applied migration version records from the Hasura metadata database. RemoveVersions deletes the schema_migrations table rows for the given versions; any database connectivity failure, permission problem, or locked table surfaces here wrapped with %w.

Source

Thrown at cli/commands/scripts_update_config_v2.go:404

								return errors.E(op, fmt.Errorf("error in removing file: %w", err))
							}
						}
					}

					upVersions = append(upVersions, version)
				}
			}

			ec.Spin("Removing versions from database...")

			migrateDrv, err := migrate.NewMigrate(ec, true, "", hasura.SourceKindPG)
			if err != nil {
				return errors.E(op, fmt.Errorf("unable to initialize migrations driver: %w", err))
			}

			err = migrateDrv.RemoveVersions(upVersions)
			if err != nil {
				return errors.E(op, fmt.Errorf("unable to remove versions from database: %w", err))
			}
			// update current config to v2
			ec.Spin("Updating current config to 2")
			os.Setenv("HASURA_GRAPHQL_VERSION", "2")
			os.Setenv("HASURA_GRAPHQL_METADATA_DIRECTORY", metadataDir)
			os.Setenv("HASURA_GRAPHQL_ACTION_KIND", ec.Viper.GetString("actions.kind"))
			os.Setenv(
				"HASURA_GRAPHQL_ACTION_HANDLER_WEBHOOK_BASEURL",
				ec.Viper.GetString("actions.handler_webhook_baseurl"),
			)

			defer func() {
				// unset env
				os.Unsetenv("HASURA_GRAPHQL_VERSION")
				os.Unsetenv("HASURA_GRAPHQL_METADATA_DIRECTORY")
				os.Unsetenv("HASURA_GRAPHQL_ACTION_KIND")
				os.Unsetenv("HASURA_GRAPHQL_ACTION_HANDLER_WEBHOOK_BASEURL")
			}()

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Verify the metadata database is reachable and credentials valid (psql $HASURA_GRAPHQL_DATABASE_URL -c 'select 1')
  2. Re-run the update command; RemoveVersions is idempotent for missing versions
  3. Check postgres logs for lock waits or permission denials on schema_migrations, grant DELETE if missing
  4. If the DB is irrecoverable, restore from backup and restart the v2 upgrade
Defensive patterns

Strategy: retry

Validate before calling

// before running update-project-v2, check metadata DB reachability
if err := pingDB(os.Getenv("HASURA_GRAPHQL_DATABASE_URL")); err != nil { log.Fatal(err) }

Try / catch

if err := updateCmd.RunE(updateCmd, args); err != nil {
    if strings.Contains(err.Error(), "unable to remove versions from database") {
        // inspect wrapped cause, fix DB connectivity, retry
    }
}

Prevention

When it happens

Trigger: Running `hasura scripts update-project-v2` (or the RunE path in scripts_update_config_v2.go) against a server whose postgres metadata database is unreachable, the hasura user lacks DELETE on schema_migrations, or a concurrent migration is holding a lock.

Common situations: Database URL points to a stopped container; metadata DB credentials rotated mid-operation; running the v2 migration while another CLI instance or server is applying migrations.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/de3ba0c7c42b5b23. Report an issue: GitHub.