diff --git a/internal/backends/collection_test.go b/internal/backends/collection_test.go index 206fd27fbfbc..1b0a9328f124 100644 --- a/internal/backends/collection_test.go +++ b/internal/backends/collection_test.go @@ -223,7 +223,6 @@ func TestCollectionStats(t *testing.T) { func TestCollectionCompact(t *testing.T) { t.Skip("https://github.com/FerretDB/FerretDB/issues/3484") - t.Skip("https://github.com/FerretDB/FerretDB/issues/3469") t.Parallel() diff --git a/internal/backends/sqlite/collection.go b/internal/backends/sqlite/collection.go index 962a5da60020..dfb3bc076d56 100644 --- a/internal/backends/sqlite/collection.go +++ b/internal/backends/sqlite/collection.go @@ -331,7 +331,33 @@ func (c *collection) Stats(ctx context.Context, params *backends.CollectionStats // Compact implements backends.Collection interface. func (c *collection) Compact(ctx context.Context, params *backends.CompactParams) (*backends.CompactResult, error) { - // TODO https://github.com/FerretDB/FerretDB/issues/3469 + var err error + q := `PRAGMA incremental_vacuum` + + db := c.r.DatabaseGetExisting(ctx, c.dbName) + if db == nil { + return nil, backends.NewError( + backends.ErrorCodeDatabaseDoesNotExist, + lazyerrors.Errorf("no ns %s.%s", c.dbName, c.name), + ) + } + + coll := c.r.CollectionGet(ctx, c.dbName, c.name) + if coll == nil { + return nil, backends.NewError( + backends.ErrorCodeCollectionDoesNotExist, + lazyerrors.Errorf("no ns %s.%s", c.dbName, c.name), + ) + } + + if params != nil && params.Full { + q = `VACUUM` + } + + if _, err = db.ExecContext(ctx, q); err != nil { + return nil, lazyerrors.Error(err) + } + return new(backends.CompactResult), nil }