{"record":{"id":"dfd87b9a91296e69","repo":"apache/answer","slug":"insert-site-info-failed-w","errorCode":null,"errorMessage":"insert site info failed: %w","messagePattern":"insert site info failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/migrations/v10.go","lineNumber":87,"sourceCode":"\t}\n\tif exist {\n\t\tsiteUsers.DefaultAvatar = gjson.Get(interfaceSiteInfo.Content, \"default_avatar\").String()\n\t}\n\tdata, _ := json.Marshal(siteUsers)\n\n\texist, err = x.Context(ctx).Get(&entity.SiteInfo{Type: constant.SiteTypeUsers})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get config failed: %w\", err)\n\t}\n\tif !exist {\n\t\tusersSiteInfo := &entity.SiteInfo{\n\t\t\tType:    constant.SiteTypeUsers,\n\t\t\tContent: string(data),\n\t\t\tStatus:  1,\n\t\t}\n\t\t_, err = x.Context(ctx).Insert(usersSiteInfo)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"insert site info failed: %w\", err)\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":69,"sourceCodeEnd":92,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/migrations/v10.go#L69-L92","documentation":"Fires in the v10 migration addLoginLimitations when the INSERT of the default users site-info row (entity.SiteInfo type SiteTypeUsers) fails against the database. This means the migration could not seed the users site configuration (allow-update flags and default avatar); the wrapped cause is the SQL insert error (e.g. duplicate key, connection loss, schema mismatch).","triggerScenarios":"x.Context(ctx).Insert(usersSiteInfo) errors: INSERT privilege denied, duplicate type='users' row inserted concurrently, table/column mismatch, or connection drop.","commonSituations":"Two migration processes racing to seed the same row; migration user read-only; site_info schema altered manually so required columns are missing.","solutions":["Check the wrapped DB error (duplicate key vs privilege)","Grant INSERT privilege on site_info","Run migrations from a single instance or use a lock to avoid duplicate inserts","Verify site_info schema matches entity.SiteInfo then re-run"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// pre-check for existing users row to avoid duplicate-key races\nhas, _ := engine.SQL(\"SELECT COUNT(*) FROM site_info WHERE type=?\", \"users\").Count()\nif has > 0 {\n    return fmt.Errorf(\"users site info already exists; skip seeding\")\n}","typeGuard":null,"tryCatchPattern":"if err := migrations.Migrate(db); err != nil {\n    if strings.Contains(err.Error(), \"insert site info failed\") {\n        log.Errorf(\"could not seed users config (privileges or duplicate): %v\", err)\n    }\n    return err\n}","preventionTips":["Grant INSERT privilege on site_info to the migration user","Prevent concurrent migration runs with a lock or single runner","Keep entity.SiteInfo in sync with the actual table schema","Use INSERT-if-absent semantics (unique index on type) to make seeding idempotent"],"tags":["database","migration","insert-failed","site-config"],"backgroundTag":"migration-config-insert-failed","analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}