Setting Secure Store flag that database structure is properly created
Details
After successful migration process DatabaseManagerStatus should equals WORKABLE
Diff Detail
- Repository
- rCOMM Comm
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
This looks like an inaccurate dependency flow to me. DatabaseManager provides getQueryExecutor method that allows to execute database queries in a way that is agnostic of the type of database used. This means it is an abstraction above SQLiteQueryExecutor, so SQLiteQueryExecutor should not call its methods. Looking at this differential, migrate() of SQLiteQueryExecutor is the only place we call this function from. Perhaps we could implement it here? Or even insert its code directly into relevant places in migrate method (due to its simplicity? Necessary constants to implement this method could be moved to DatabaseQueryExecutor header file or even refactored to some new common header file with database-related constants.
Yes, you're correct, it was a really bad idea to call DatabaseManager's method from the SQLiteQueryExecutor level. But having in mind what I've pointed in this comment: https://phab.comm.dev/D5993#183452 I would suggest a slightly different approach.
Maybe it'll be better to call it after we successfully create a query executor (thread_local variable) which will mean that DB structure is not malformed, in getQueryExecutor() function, probably with adding some variable to DatabaseManager to avoid writing to secure store each time getQueryExecutor is called. What do you think?
This approach sounds reasonable to me. When implementing this approach it might be helpful to consider https://en.cppreference.com/w/cpp/thread/once_flag and https://en.cppreference.com/w/cpp/thread/call_once (an easy way to make something idempotent in C++).
Requesting changes until mutually agreed approach that was discussed above is implemented.
native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp | ||
---|---|---|
21–23 ↗ | (On Diff #20684) | Maybe add a comment explaining that creating an instance means that the migrations succeeded and we can assume the db is usable. |
61 ↗ | (On Diff #20684) | Do we need the curly brackets? |
native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.h | ||
10 ↗ | (On Diff #20684) | We should import it from std in this file |
native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp | ||
---|---|---|
61 ↗ | (On Diff #20684) | Same reason as in https://phab.comm.dev/D5991?id=20682#inline-42549 |
native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.h | ||
10 ↗ | (On Diff #20684) | sure, adding #include <mutex> |