{"record":{"id":"4d72f986db6535ab","repo":"zitadel/zitadel","slug":"s-s-w-4d72f9","errorCode":null,"errorMessage":"%s %s: %w","messagePattern":"%s %s: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/setup/40.go","lineNumber":52,"sourceCode":"func (mig *InitPushFunc) Execute(ctx context.Context, _ eventstore.Event) (err error) {\n\tconn, err := mig.dbClient.Conn(ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer func() {\n\t\tcloseErr := conn.Close()\n\t\tlogging.OnError(ctx, closeErr).Debug(\"failed to release connection\")\n\t\t// Force the pool to reopen connections to apply the new types\n\t\tmig.dbClient.Pool.Reset()\n\t}()\n\tstatements, err := mig.prepareStatements(ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\tfor _, stmt := range statements {\n\t\tlogging.Info(ctx, \"execute statement\", \"file\", stmt.file, \"migration\", mig.String())\n\t\tif _, err := conn.ExecContext(ctx, stmt.query); err != nil {\n\t\t\treturn fmt.Errorf(\"%s %s: %w\", mig.String(), stmt.file, err)\n\t\t}\n\t}\n\t// close idle connections to prevent them from using the old prepared statement with the wrong type\n\t// and having wrong plan of `eventstore.command2`-type\n\tfor _, conn := range mig.dbClient.Pool.AcquireAllIdle(ctx) {\n\t\tlogging.OnError(ctx, conn.Conn().Close(ctx)).Debug(\"failed to close idle connection\")\n\t\tconn.Release()\n\t}\n\n\treturn nil\n}\n\nfunc (mig *InitPushFunc) String() string {\n\treturn \"40_init_push_func_v4\"\n}\n\nfunc (mig *InitPushFunc) prepareStatements(ctx context.Context) ([]statement, error) {\n\tfuncTmpl, err := template.ParseFS(initPushFunc, mig.filePath(fileFunc))","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/zitadel/zitadel/blob/13948f2bcd6f257794dbd6d342c2ac30bc88fe54/cmd/setup/40.go#L34-L70","documentation":"The InitPushFunc migration (40) executes its SQL statements and wraps failures as fmt.Errorf(\"%s %s: %w\", mig.String(), stmt.file, err) — \"<migration> <file>: <cause>\". It then closes idle pool connections because old prepared statements would otherwise replay with wrong types; the wrapper pinpoints which SQL file of migration 40 failed.","triggerScenarios":"ExecContext failure on any statement of 40_init_push_func_v4: SQL syntax/type errors, missing eventstore.command2 type, or insufficient privileges to create functions.","commonSituations":"Upgrading from a ZITADEL version whose push function/aggregate type differs; DB user lacking CREATE FUNCTION privilege; prepared-statement type conflicts from pooled connections.","solutions":["Check the named SQL file and the wrapped pg error; run the statement manually to see the exact failure.","Ensure the DB user can create/replace functions and types in the eventstore schema.","Confirm the source ZITADEL version is one that migration 40 supports upgrading from."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// check privileges to create functions\nSELECT has_schema_privilege(current_user, 'eventstore', 'CREATE');","typeGuard":null,"tryCatchPattern":"if _, err := conn.ExecContext(ctx, stmt.query); err != nil {\n    var pgErr *pgconn.PgError\n    if errors.As(err, &pgErr) { /* handle by pgErr.Code */ }\n    return fmt.Errorf(\"%s %s: %w\", mig.String(), stmt.file, err)\n}","preventionTips":["Follow the documented upgrade sequence so prerequisite migrations created the required types.","Grant CREATE on the eventstore schema to the setup user.","Close/reopen pooled connections after DDL that changes types (as this migration does)."],"tags":["database","sql","migration","postgres"],"backgroundTag":"database-query-failed","analyzedSha":"13948f2bcd6f257794dbd6d342c2ac30bc88fe54","analyzedAt":"2026-09-06T10:16:19.814Z","contentChangedAt":"2026-09-06T10:16:19.814Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}