Repository navigation
Conversation
ref https://linear.app/ghost/issue/DYA-361 Nothing in NQL said what a filter means under a negation, null or a related row, so each kind of key answered differently: tag:-null selects the posts with no tags while image:-null selects the posts with an image, and image:-'a.jpg' leaves out the posts with no image at all. The new test states one rule for every kind of key and runs it against the database: a plain column, one that can be NULL, a one-to-one relation, a many-to-many relation and one of its columns that can be NULL, a join table's own column alone and beside its relation, an aggregate, a key that stands for several conditions such as primary_tag, and $elemMatch as Ghost's custom field filters write it. Each filter lists the posts the rule selects. Where the code selects other posts today, the case records them as a known deviation, so the test passes now and a change that brings a filter in line with the rule has to remove the entry, which shows in its diff exactly which filters it changes. The same filters are matched against posts as JSON objects in memory, as routes.yaml does, and the equalities the rule implies, such as k:-a selecting what -(k:a) selects, are checked for every kind of key, with the ones that fail today listed. The $elemMatch filters have no deviation, so they pin the rows Ghost's custom field filters select today.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #320 +/- ##
=======================================
Coverage 85.56% 85.56%
=======================================
Files 9 9
Lines 2418 2418
Branches 510 513 +3
=======================================
Hits 2069 2069
Misses 343 343
Partials 6 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ref https://linear.app/ghost/issue/DYA-361
What it adds
A test that states what a filter means under a negation,
nullor a related row, for every kind of key, and records where the code disagrees today. It changes no code: every filter selects the same rows before and after this pull request.The rule it states: every key names the set of values a row has for it, and NULL is never a value. A column or a one-to-one relation has no value or one; a to-many relation has one value per related row whose column isn't NULL; an aggregate has exactly one number. Every negation selects exactly the rows its positive form doesn't.
k:v/k:-vk:null/k:-nullk:[a,b]/k:-[a,b]k:a,k:b/k:-a+k:-bk:[null,a]/k:-[null,a]k:null,k:a/k:-null+k:-ak:~v/k:-~vEach case is a filter and the posts the rule selects. Where the code selects other posts today, the case says so:
The kinds of key covered: a plain column, one that can be NULL, a one-to-one relation, a many-to-many relation and one of its columns that can be NULL, a join table's own column alone and beside its relation, an aggregate, a key that stands for several conditions (
primary_tag), and$elemMatchas Ghost's member custom field filters write it. The same filters are matched against the posts as JSON objects, asroutes.yamlmatches them. For every kind of key it checks the equalities the rule implies (k:-aselects what-(k:a)selects,k:nullandk:-nullsplit all rows, a query rendered to SQL once and then run selects the same rows, and so on), with the ones that don't hold today listed.Scope
In: the test, its tables and fixtures. Out: any change to what a filter selects. A later change that brings a filter in line with the rule has to delete that filter's
todayentry, so its diff shows exactly which filters it changes. The$elemMatchcases have no deviation and pin the rows Ghost's custom field filters select today.Two readings are decisions rather than the rule table itself, and are stated at the top of the test: conditions on different columns of one relation in one
+group read the same related row, as they do today (tag:news+tags.visibility:internalselects no post here); and a join table condition beside its relation picks which related rows the condition reads.Testing
pnpm --filter @tryghost/nql teston SQLite. The rule's rows were cross-checked against an independent prototype of the rule, which agrees on every case except the join table ones it doesn't route.