{"record":{"id":"88c0f5d30cc0bc7b","repo":"golang-migrate/migrate","slug":"unknown-lock-strategy-s","errorCode":null,"errorMessage":"unknown lock strategy \"%s\"","messagePattern":"unknown lock strategy \"(.+?)\"","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"database/pgx/pgx.go","lineNumber":257,"sourceCode":"\nfunc (p *Postgres) Close() error {\n\tconnErr := p.conn.Close()\n\tdbErr := p.db.Close()\n\tif connErr != nil || dbErr != nil {\n\t\treturn fmt.Errorf(\"conn: %v, db: %v\", connErr, dbErr)\n\t}\n\treturn nil\n}\n\nfunc (p *Postgres) Lock() error {\n\treturn database.CasRestoreOnErr(&p.isLocked, false, true, database.ErrLocked, func() error {\n\t\tswitch p.config.LockStrategy {\n\t\tcase LockStrategyAdvisory:\n\t\t\treturn p.applyAdvisoryLock()\n\t\tcase LockStrategyTable:\n\t\t\treturn p.applyTableLock()\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"unknown lock strategy \\\"%s\\\"\", p.config.LockStrategy)\n\t\t}\n\t})\n}\n\nfunc (p *Postgres) Unlock() error {\n\treturn database.CasRestoreOnErr(&p.isLocked, true, false, database.ErrNotLocked, func() error {\n\t\tswitch p.config.LockStrategy {\n\t\tcase LockStrategyAdvisory:\n\t\t\treturn p.releaseAdvisoryLock()\n\t\tcase LockStrategyTable:\n\t\t\treturn p.releaseTableLock()\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"unknown lock strategy \\\"%s\\\"\", p.config.LockStrategy)\n\t\t}\n\t})\n}\n\n// https://www.postgresql.org/docs/9.6/static/explicit-locking.html#ADVISORY-LOCKS","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/database/pgx/pgx.go#L239-L275","documentation":"Postgres.Lock acquires a migration lock using the configured LockStrategy. This error is returned from the default branch of the strategy switch when p.config.LockStrategy is neither the advisory-lock nor table-lock strategy, meaning the strategy value is empty or unrecognized.","triggerScenarios":"Constructing a pgx Config (or WithInstance/Open path) with LockStrategy set to a value other than pgx.LockStrategyAdvisory or pgx.LockStrategyTable (e.g. an empty string, or a user-supplied string like \"advisory\" that was never converted to the typed constant) and then calling Lock.","commonSituations":"Hand-building a Config instead of relying on defaults (zero-value empty string); parsing a user string into LockStrategy without validating against the defined constants; switching from another driver's config struct that names lock strategies differently.","solutions":["Set LockStrategy to a defined constant: pgx.LockStrategyAdvisory or pgx.LockStrategyTable.","Leave LockStrategy zero/unset only if the library's defaults apply; otherwise always assign a constant, never a raw string.","Print the config value and compare against the exported LockStrategy constants to catch typos.","If accepting user input, validate/parse it into a valid LockStrategy before constructing Config."],"exampleFix":"// before\ncfg := &pgx.Config{MigrationsTable: \"schema_migrations\", LockStrategy: \"advisory\"}\n// after\ncfg := &pgx.Config{MigrationsTable: \"schema_migrations\", LockStrategy: pgx.LockStrategyAdvisory}","handlingStrategy":"validation","validationCode":"func validateLockStrategy(s pgx.LockStrategy) error {\n    if s != pgx.LockStrategyAdvisory && s != pgx.LockStrategyTable {\n        return fmt.Errorf(\"unsupported lock strategy %q\", s)\n    }\n    return nil\n}","typeGuard":"func isKnownLockStrategy(s pgx.LockStrategy) bool {\n    return s == pgx.LockStrategyAdvisory || s == pgx.LockStrategyTable\n}","tryCatchPattern":"if err := drv.Lock(); err != nil {\n    if strings.Contains(err.Error(), \"unknown lock strategy\") {\n        return fmt.Errorf(\"set Config.LockStrategy to pgx.LockStrategyAdvisory or pgx.LockStrategyTable: %w\", err)\n    }\n    return err\n}","preventionTips":["Always assign LockStrategy using the exported constants, never raw strings","Validate user-supplied strategy names against the constants at config load time","Rely on library defaults instead of hand-building Config when possible"],"tags":["postgresql","locking","config","invalid-enum"],"backgroundTag":"invalid-enum-config-value","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}