-
Notifications
You must be signed in to change notification settings - Fork 309
Use Drift and SQLite for data storage #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I've rebased this a couple of times as the related work has progressed, and made some further revisions earlier this week. Just pushed the current version. This still needs end-to-end testing before I'd want to merge it. That's a lot closer now that #11 is done, and #55. The end-to-end testing will basically consist of implementing #34, storing login credentials. |
Just the other day we were talking about this get-server-settings property, and I explained why it's important for a mobile client to use it: https://chat.zulip.org/#narrow/stream/378-api-design/topic/uri.20to.20url.20compatibility/near/1549242 But apparently when I wrote this code a couple of weeks earlier, I'd forgotten about that, oops. Fix it. It's particularly useful that we fix this before we start keeping the list of accounts in a database, so that there's no legacy of some people's devices having a non-canonicalized URL lying around.
This removes the one place where we really use the fact that we've had Account as a subtype of Auth. We'll be giving up that subtyping as part of getting Account from a database ORM.
This frees us up to switch to an Account type that's generated to correspond to a database table.
This will let LiveGlobalStore and TestGlobalStore diverge in how the data is ultimately stored and how the account IDs are assigned, while sharing the code to maintain the in-Dart cache.
…_dev These are the dependencies called for by the Drift docs: https://drift.simonbinder.eu/docs/getting-started/#adding-the-dependency
Also add a .gitattributes file, excluding `*.g.dart` files from diffs. We didn't really need this when the only such files were the JSON serialization/deserialization files in the API bindings, because those are pretty compact; but this generated ORM code is much longer and makes it more necessary.
This will keep things simple when we start storing these in the database.
OK! This is now tested end to end, and I think it's complete. Please take a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exciting! 🎉
See one comment below, then please merge at will.
@override | ||
List<Set<Column<Object>>> get uniqueKeys => [ | ||
{realmUrl, userId}, | ||
{realmUrl, email}, | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could add a TODO in lib/widgets/login.dart to handle exceptions thrown because of this, or maybe check GlobalStore.accountIds
before sending a bad insert to the database.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thought. I added one TODO(log) to log database errors (which we should do in a general way down in the Drift layer), and also a TODO(#35) in lib/widgets/login.dart to give the user feedback if the account is a duplicate.
We didn't really need to do this as a migration, because we already know we need this column and so we could have included it from the start. But this lets us exercise Drift's support for migrations, and for testing migrations.
Thanks for the review! Done. |
This happens automatically if you rerun build_runner. Seems like its omission was basically a mismerge between 901a99e, when it was merged early from zulip#84: zulip#84 (comment) and 780b092 / zulip#22, which added this file. Chalk it up as another occasion where zulip#60 would have helped keep things clean.
This happens automatically if you rerun build_runner. Seems like its omission was basically a mismerge between 901a99e, when it was merged early from zulip#84: zulip#84 (comment) and 780b092 / zulip#22, which added this file. Chalk it up as another occasion where zulip#60 would have helped keep things clean.
Fixes #13.
Fixes #34.
originally:
Toward #13.
This installs Drift as a dependency, sets up a schema for an accounts table, and performs a migration on that table. It also adds tests for the database schema and the migration, to let us see how those look.
I won't want to merge something like this until I've tested it more end-to-end, which will require some other work including #20 and #21. But I think the branch is otherwise ready, apart from a couple of polish issues.