{"record":{"id":"80c407145d41af1e","repo":"gofr-dev/gofr","slug":"w-s-w","errorCode":null,"errorMessage":"%w: %s: %w","messagePattern":"%w: (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/migration/surreal_db.go","lineNumber":73,"sourceCode":")\n\nfunc getMigrationTableQueries() []string {\n\treturn []string{\n\t\t\"DEFINE TABLE IF NOT EXISTS gofr_migrations SCHEMAFULL;\",\n\t\t\"DEFINE FIELD IF NOT EXISTS id ON gofr_migrations TYPE string;\",\n\t\t\"DEFINE FIELD IF NOT EXISTS version ON gofr_migrations TYPE number;\",\n\t\t\"DEFINE FIELD IF NOT EXISTS method ON gofr_migrations TYPE string;\",\n\t\t\"DEFINE FIELD IF NOT EXISTS start_time ON gofr_migrations TYPE datetime;\",\n\t\t\"DEFINE FIELD IF NOT EXISTS duration ON gofr_migrations TYPE number;\",\n\t\t\"DEFINE INDEX IF NOT EXISTS version_method ON gofr_migrations COLUMNS version, method UNIQUE;\",\n\t}\n}\n\nfunc (s surrealMigrator) checkAndCreateMigrationTable(c *container.Container) error {\n\t// Create migration table directly\n\tfor _, q := range getMigrationTableQueries() {\n\t\tif _, err := s.SurrealDB.Query(context.Background(), q, nil); err != nil {\n\t\t\treturn fmt.Errorf(\"%w: %s: %w\", errExecuteQuery, q, err)\n\t\t}\n\t}\n\n\treturn s.migrator.checkAndCreateMigrationTable(c)\n}\n\n// surrealVersionToInt64 converts the `version` field returned by SurrealDB into an int64.\n// The SurrealDB driver decodes a `number` column into different Go types depending on the\n// stored value and driver version (e.g. int or int64 or uint64 or float64 over CBOR\n// responses), so we handle each numeric type explicitly. Unknown/absent values default to 0.\nfunc surrealVersionToInt64(v any) int64 {\n\tswitch n := v.(type) {\n\tcase int64:\n\t\treturn n\n\tcase int:\n\t\treturn int64(n)\n\tcase uint64:\n\t\tif n > math.MaxInt64 {","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/migration/surreal_db.go#L55-L91","documentation":"This wrapped error is produced by surrealMigrator.checkAndCreateMigrationTable when one of the queries that creates the SurrealDB migration table fails. The format `%w: %s: %w` embeds the sentinel errExecuteQuery, the exact failing query text, and the underlying driver error, so the full message reads like 'failed to execute migration query: <query>: <driver error>'. It means the migration table could not be created and migrations cannot proceed.","triggerScenarios":"Running GoFr migrations with a SurrealDB datasource where s.SurrealDB.Query(context.Background(), q, nil) errors for any query in getMigrationTableQueries() — bad connection, insufficient permissions, unsupported syntax.","commonSituations":"SurrealDB user lacks permission to define tables; SurrealDB running an older version that rejects the query syntax; endpoint misconfigured so connection drops mid-query.","solutions":["Read the innermost wrapped error in the message chain — it names the actual SurrealDB failure (auth, permission, syntax).","Run the failing query (printed in the error) manually in a SurrealDB shell to reproduce and debug.","Grant the configured SurrealDB user permission to create tables in the target namespace/database.","Confirm SurrealDB server version compatibility with the GoFr driver queries."],"exampleFix":"// before: user without define-table permission\nDEFINE USER app PASSWORD '...' ROLES EDITOR;\n// after: grant permissions allowing table creation\nDEFINE USER app PASSWORD '...' ROLES OWNER;","handlingStrategy":"try-catch","validationCode":"// validate permissions by attempting a harmless query first\nif _, err := db.Query(ctx, \"RETURN 1\", nil); err != nil {\n\treturn fmt.Errorf(\"surrealdb not ready: %w\", err)\n}","typeGuard":"func isSetupErr(err error) bool {\n\treturn errors.Is(err, errExecuteQuery)\n}","tryCatchPattern":"err := migrator.checkAndCreateMigrationTable(c)\nif err != nil {\n\t// message chain: sentinel : query : driver error — parse innermost first\n\tlog.Printf(\"setup failed: %v\", err)\n\treturn err\n}","preventionTips":["Grant the migration user OWNER/EDIT rights on the target namespace/database.","Copy the failing query from the error and run it in surreal sql REPL to debug.","Check SurrealDB server logs for the rejected statement.","Keep SurrealDB version compatibility documented in your deployment notes."],"tags":["surrealdb","migration","ddl","gofr"],"backgroundTag":"migration-table-setup-failed","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}