{"record":{"id":"de3ba0c7c42b5b23","repo":"hasura/graphql-engine","slug":"unable-to-remove-versions-from-database-w","errorCode":null,"errorMessage":"unable to remove versions from database: %w","messagePattern":"unable to remove versions from database: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/commands/scripts_update_config_v2.go","lineNumber":404,"sourceCode":"\t\t\t\t\t\t\t\treturn errors.E(op, fmt.Errorf(\"error in removing file: %w\", err))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tupVersions = append(upVersions, version)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tec.Spin(\"Removing versions from database...\")\n\n\t\t\tmigrateDrv, err := migrate.NewMigrate(ec, true, \"\", hasura.SourceKindPG)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.E(op, fmt.Errorf(\"unable to initialize migrations driver: %w\", err))\n\t\t\t}\n\n\t\t\terr = migrateDrv.RemoveVersions(upVersions)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.E(op, fmt.Errorf(\"unable to remove versions from database: %w\", err))\n\t\t\t}\n\t\t\t// update current config to v2\n\t\t\tec.Spin(\"Updating current config to 2\")\n\t\t\tos.Setenv(\"HASURA_GRAPHQL_VERSION\", \"2\")\n\t\t\tos.Setenv(\"HASURA_GRAPHQL_METADATA_DIRECTORY\", metadataDir)\n\t\t\tos.Setenv(\"HASURA_GRAPHQL_ACTION_KIND\", ec.Viper.GetString(\"actions.kind\"))\n\t\t\tos.Setenv(\n\t\t\t\t\"HASURA_GRAPHQL_ACTION_HANDLER_WEBHOOK_BASEURL\",\n\t\t\t\tec.Viper.GetString(\"actions.handler_webhook_baseurl\"),\n\t\t\t)\n\n\t\t\tdefer func() {\n\t\t\t\t// unset env\n\t\t\t\tos.Unsetenv(\"HASURA_GRAPHQL_VERSION\")\n\t\t\t\tos.Unsetenv(\"HASURA_GRAPHQL_METADATA_DIRECTORY\")\n\t\t\t\tos.Unsetenv(\"HASURA_GRAPHQL_ACTION_KIND\")\n\t\t\t\tos.Unsetenv(\"HASURA_GRAPHQL_ACTION_HANDLER_WEBHOOK_BASEURL\")\n\t\t\t}()","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/commands/scripts_update_config_v2.go#L386-L422","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the metadata database is reachable and credentials valid (psql $HASURA_GRAPHQL_DATABASE_URL -c 'select 1')","Re-run the update command; RemoveVersions is idempotent for missing versions","Check postgres logs for lock waits or permission denials on schema_migrations, grant DELETE if missing","If the DB is irrecoverable, restore from backup and restart the v2 upgrade"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// before running update-project-v2, check metadata DB reachability\nif err := pingDB(os.Getenv(\"HASURA_GRAPHQL_DATABASE_URL\")); err != nil { log.Fatal(err) }","typeGuard":null,"tryCatchPattern":"if err := updateCmd.RunE(updateCmd, args); err != nil {\n    if strings.Contains(err.Error(), \"unable to remove versions from database\") {\n        // inspect wrapped cause, fix DB connectivity, retry\n    }\n}","preventionTips":["Ensure metadata DB is up before starting the v2 upgrade","Run only one CLI migration operation at a time","Take a metadata DB backup before update-project-v2"],"tags":["database","migrations","hasura-cli","config-v2"],"backgroundTag":"database-migration-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}