You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Eng 898 create database query functions for base dg queries (#474)
Added many parameters to node query function (renamed to getConcepts since it covers both nodes and relations.) In particular, allow to
* request nodes or relations or both
* Filter on the concept being involved in a relation
* Filter on that relation's type
* Filter on that the type of other concepts in the relation
* Filter on author of target concept or related concept
* Filter on a subset of concepts or related concepts
Added illustrative cucumber tests for the same, and did some TS cleanup of stepdefs.ts in the process.
Copy file name to clipboardExpand all lines: packages/database/README.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,10 +71,12 @@ If schema changes are deployed to `main` by another developer while you work on
71
71
72
72
There are [cucumber](https://cucumber.io/) scenarios (in `packages/database/features`) to test the flow of database operations. We have not yet automated those tests, but you should run against the local environment when developing the database. You will need to:
73
73
74
+
1. set `SUPABASE_DB=local` in `packages/database/.env`
74
75
1. Run `turbo dev` in one terminal (in the root directory)
75
-
2. In another other terminal, `cd` to this directory (`packages/database`) and run the tests with `pnpm run test`
76
+
1. In another other terminal, `cd` to this directory (`packages/database`) and run the tests with `pnpm run test`
Cucumber is a harness for the gherkin language, allowing to make tests more legible. The steps are defined as regexp in `features/step-definitions/stepdefs.ts`. Currently, we assume the database is running with `turbo dev` in another terminal.
4
+
5
+
Some of test steps were defined to clear the database (`Given the database is blank`) or to put arbitrary data in the tables (`{word} are added to the database:`) which expects the name of a table as argument, and a markdown table for the table data.
6
+
7
+
The latter step requires some further explanations:
8
+
9
+
A lot of database objects use foreign keys, so we need to refer to numeric database identifiers. Those are defined by the database. To allow this to work, we have a pseudo-column called `$id`, which is a string alias that corresponds to the database numeric `id`. Make sure each value in that column is unique. We keep a dictionary of those aliases to the database numeric `id` in cucumber. When interpreting the table, if any other column is prefixed by a `_`, we will recursively search for strings and from the alias set and replace them with the appropriate database ids. Note that inserts are made in bulk, so you may need to break up your inserts according to dependencies. For example:
10
+
11
+
- Adding a schema first
12
+
`And Concept are added to the database:`
13
+
14
+
| $id | name | @is_schema |
15
+
| alias1 | Claim | true |
16
+
17
+
- Then a concept referring to the schema
18
+
`And Concept are added to the database:`
19
+
| $id | name | @is_schema |\_schema_id |
20
+
| alias2 | claim 1 | false | alias1 |
21
+
22
+
Also, cucumber treats all columns as strings; if they contain a non-string literal (essentially number, boolean or JSON) you can use the `@` prefix in the column name so the cell value will be parsed as json before sending to the database. (`@` comes before `_` if both are used.)
23
+
24
+
Other steps that require explanation:
25
+
26
+
-`a user logged in space {word} and calling getConcepts with these parameters: {string}`
27
+
-`Then query results should look like this`
28
+
29
+
This comes in pairs: The results from the query (whose parameters are defined as json) are checked against a table, using the same syntax as above. Only the columns defined are checked for equivalence.
30
+
31
+
-`the user {word} opens the {word} plugin in space {word}`.
32
+
33
+
This both creates the space and an account tied to that space. Because tying spaces and accounts goes through an edge function, it is the only good way to do both.
0 commit comments