Closed samanthagottlieb closed 1 year ago
Can see this running in CODE, looks good! Top work. One non-blocking comment.
A quick note that the title of this PR isn't quite accurate as I understand it – we're adding a rule order column to the draft rules table, but not sorting by it yet!
I think that would be good to do – all we'd need is an order by clause for our find methods in
DbRuleDraft
. Happy for us to do this in this PR, or a separate PR.
Good point on the PR title! I've added an ORDER BY
clause to the find methods. In terms of testing this (or testing any query using the ScalaJDBC lib) I ran the app locally, played around in the Typerighter UI, looked at the Docker logs, copied the latest query, and ran this in my IntelliJ query console to check the results were ordered by rule_order
. Is this the best way to go about it, or is there a more efficient way?
@samanthagottlieb that sounds great. It's only a small change, what you did would have worked well (guessing the presence of the ORDER BY clause was enough to convince you it was doing the right thing). Quickest feedback loop I'd reach for to check this is probably to write a test with a couple of rules having differing rule_order
values, and using ~testOnly
to iterate.
@samanthagottlieb that sounds great. It's only a small change, what you did would have worked well (guessing the presence of the ORDER BY clause was enough to convince you it was doing the right thing). Quickest feedback loop I'd reach for to check this is probably to write a test with a couple of rules having differing
rule_order
values, and using~testOnly
to iterate.
Thanks for this Jon, perhaps I merged prematurely and should have added a test or two!
What does this change?
This adds a
rule_order
column to therules_draft
table, which will be used to determine prioritisation of rules that may conflict.Previously (before the TR manager), rule order was determined by the order of the rule in the spreadsheet. This order has been maintained in the database by the rule id -
rule_order
in therules_live
table was determined by copying this id when a rule is published.When there is already data in the database, the logic added in this PR copies the
id
inrules_draft
into a newrule_order
column (done as an evolution). When a new rule is added, a query will find the latest rule order and increment this by 1. If there is no data in the database, therule_order
will be assigned according to the spreadsheet row index, thus maintaining the spreadsheet order.Trello card is here.
Next
Sort by rule order on the client. In future we'll look at implementing a way for users to rearrange the order of conflicting rules.
How to test
This can be tested locally by running
sbt
, and running the tests with:All tests should pass and the latest evolution should be applied. If your database already contained data, all rows in the
rules_draft
column should be populated, with the values ofrules_draft
matching the values of the rule'sid
.To test the logic when the database starts without any tables, drop your local database tables, run the manager app and press the big red
Destroy all rules in the manager...
button in the UI. Therules_draft
table should be created with arule_order
column. The value ofrule_order
won't necessarily match theid
as theid
auto increment counter does not reset automatically.This has been tested on CODE. Instructions here can be followed to connect to the CODE database.