Skip to content

goodm 0.7.0

Choose a tag to compare

@dwoolworth dwoolworth released this 24 Oct 23:12
· 8 commits to main since this release
00ec44c

goodm 0.7.0 closes the MongoDB feature gaps found in a review of 0.6.1 and fixes the correctness bugs that review and the follow-up adversarial reviews surfaced. It contains breaking changes; see the end of these notes. Full detail is in the CHANGELOG.

Tested against

MongoDB Go
6.0.28, 7.0.45, 8.0.34 as single-node replica sets 1.21, 1.22, 1.23 in CI; 1.26 locally

The full suite runs with the race detector on every combination. CI now starts each server as a replica set, so transactions and write concern behavior are exercised on every run (#10).

Indexes

  • Field tags index=-1, index=hashed, index=text, index=2dsphere, sparse, and ttl=<duration|seconds>.
  • CompoundIndex gains Sparse, Name, ExpireAfterSeconds (with TTL(time.Duration)), PartialFilter, and Collation; Fields entries accept -field and field:text/hashed/2dsphere markers.
  • Tags inside subdocuments create dotted-path indexes.
  • One resolved IndexDefinition list per schema drives Enforce, Migrate, and goodm inspect; Enforce detects mismatches in keys, uniqueness, sparseness, TTL, partial filter, and collation, and Migrate plans rebuilds instead of parsing index names. Partial filters are normalized and compared canonically.

Query layer

  • FindByID, Count, Exists, Distinct, FindOneAndUpdate, FindOneAndReplace, FindOneAndDelete.
  • Projection, hint, collation, and batch size on finds; upsert (Upsert()), array filters, hint, and collation on UpdateOne/UpdateMany; hint and collation on deletes.
  • Aggregation options (AllowDiskUse, collation, hint, batch size) and new stages; Pipeline now runs middleware.

Bulk

  • NewBulk: a builder over BulkWrite with per-operation failure reporting.
  • SaveMany: the Update lifecycle for a slice of models, with per-document version filters and exact per-item outcomes (conflict, not found, duplicate key, write concern, transport), concurrent outside transactions and transaction-aware inside them.
  • CreateMany gains Unordered; *BulkError reports failed items with errors.Is/errors.As support and a WriteConcernError.

Errors, middleware, registry

  • ErrDuplicateKey / *DuplicateKeyError with collection, index, and field names.
  • Middleware can rewrite OpInfo.Filter and OpInfo.Pipeline; Update, UpdateFields, Delete, and SaveMany AND the rewritten filter with their own.
  • The registry is keyed by type (SchemaOf, Unregister); custom _id types are supported; Register rejects models the driver would store differently (no _id tag, goodm.Model embedded without inline, duplicate bson names, invalid inline tags).
  • UpdateFields validates its values, converts them to the field's Go type with an explicit whitelist of safe conversions, rejects immutable fields and unreachable paths, accepts dotted paths, and leaves the caller's map alone.

Fixed

  • min/max skipped zero values and truncated floats.
  • Middleware could not change the filter.
  • Schemas keyed by bare struct name collided across packages.
  • Populate ignored the referenced model's collection options.
  • Nested WithTransaction started a second session; a session without a transaction now gets one.
  • Compound text indexes always mismatched; discover lost index kinds, options, custom names, and second indexes on a field.

Breaking

  • GetAll() returns a sorted []*Schema; PlanMigration takes []*Schema.
  • Get(name) returns false for an ambiguous name; use SchemaOf.
  • FieldSchema.Min/Max are *float64.
  • min/max apply to zero values and to slice and map lengths.
  • unique/index/sparse/ttl tags inside subdocuments now create real indexes.
  • Only exported fields are schema fields; inline flattening follows the driver's rules; managed fields are found by bson name.
  • CreateMany returns *BulkError; unique violations everywhere are *DuplicateKeyError; UpdateFields returns ValidationErrors for bad values and drops undeclared subdocument keys.
  • Pipeline.Execute/Cursor run middleware.
  • Minimum Go version is 1.21.

Pull requests: #7, #8, #9, #10.