-
Notifications
You must be signed in to change notification settings - Fork 898
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
Suggestion: Switching to FluentMigrator and Linq2Db for a backup sqlite database operations #4389
Comments
Looks like noone is interested in that. Closing an issue, please reopen if I'm wrong and there is some feedback on that. |
Maybe nobody is familiar with the tools or the philosophy of use. I would be interested in your input on your question:
because Duplicati very much needs DB volunteers. I'm not one, but would like to minimize the barriers to new entrants. These tools (to the extent I could follow them) seemed like they reduced "low level" code but needed high level training. From a non-DB-person view, I find that current code is hard to read and follow. How safely can any migration be done? From a maintainability point of view, would migrated code be easier to read and follow by those who aren't DB-expert?
Duplicati does has some SQL code that should go faster. Maybe DB design is off, maybe queries are off. Any help there? There might also be some actual bugs in logic (either C# or the SQL it runs). Tracking them down in field is not possible. There are currently some cases where crashes (or kills) leave DB damaged. Rollback design is not understood. Any help?
Switching to what I guess is schema migration, there is currently a version-based DatabaseUpgrader that upgrades the Change increments are under source control. Downgrades are tough, e.g. if older Duplicati is installed. Any help there? My current view of dealing with Duplicati DB code seems to be most people are hesitant to change for fear of breaking. |
Okay, let me start with a big thank you for your pretty detailed answer, @ts678, it covers a lot of what I was curious of about core dev team. I'll set a scene first.
Lets iterate over what these proposed tools are (and it's still debatable, I'm not insisting on these, but kinda defaulting to it). FluentMigratorAlmost every app (and, as far as i can tell, duplicati is no exception) needs some way to upgrade and keep track of current versions of databases. FluentMigrator is a tool that helps with that. For example, migration that describes current schema might look something like this: And a following modification of DB would look like this: Pros:
Cons:
Linq2dbManaging schema is one problem. Second one is accessing said schema. Linq2db is an ORM that lets to rewrite SQL queries into a strongly typed LINQ queries. using(var dbContext = new BackupDb()) {
var logEntries = dbContext.LogData.OrderByDescending(l => l.Timestamp).ThenByDescending(l => l.ID).Take(50).ToList();
} Linq expression is translated into SQL script, and gets sent to db engine (in case of duplicati, it's SQLite) for processing and result is then mapped on DTO object for ease of use and compile-time type checking. Pros:
Cons:
TL;DR: Integrating those tools won't be easy and will require significant changes in DB code, but will ease future modifications. Now, about your speific concerns.
You are right that it requires some additional skills, but it's not as high as you think. Both of these tools have great (IMO) documentation and plenty of info out there to read and use. Yes, community is not as big as SQL, but these tools are pretty widespread in .NET community, and concepts of ORM and migrations are similar and wildly used in many other languages and ecosystems as well. I would consider using this tools as valuable experience.
Linq2db builds on LINQ, which is native to .NET and has plenty of resources and guides on how to use it. Learning is of course necessary, but barrier for entry is IMO not that high for an experienced .NET developer. For someone who starts in .NET that might be a bit much, but ORMs and migrations are there in other languages too, so they can reuse some of existing knowledge, and if there is nothing to reuse - it's pretty valuable thing to learn and have at least basic understanding of.
I would say yes.
I would say that yes, having an easier way to make DB queries and modify DB schema could help in optimization. It will be easier to optimize something if you'll have easier time in changing logic of this thing.
There are some tools to log executed SQL queries of course.
Yes, transactions are supported by said tools, and are pretty easy to use. It's semantics doesn't really differ from what you can find SQL (exactly because it uses SQL transactions under the hood), so learning these won't be a big challenge. I'm willing to be that DB volunteer for this transition (and although I have some understanding of DB and tools above, I'm not an expert by any stretch) and I will be happy to help duplicati more in the future, but at the same time I understand that such a big change will require lots of testing and might not sit well with everyone. After all - if core team won't be able or doesn't want to deal with ORM and FluentMigrator then it might be better to leave it as is. |
Thanks for the extensive note. I'd probably have to get at least several key people interested for this to happen. I'll go ask... Possibly after next Beta goes out (it's about time right now) would be a chance to tinker and maybe break things in Canary.
Duplicati does this in a profiling log now. As you might imagine, the SQL queries that are seen are long and tough to read. I'm not sure if this is a fair comparison, but this reminds me of some round-trip challenges that code generators may pose. Thanks again. |
Thanks @SomebodyOdd and @ts678 for the detailed thoughts. I haven't had time to read the above conversation carefully, but let me leave some brief comments here:
|
Thanks @SomebodyOdd for bringing it up! And thanks @ts678 & @warwickmm for the follow up. When I originally wrote the queries, the only substitute I could find was the NHibernate and EntityFramework-like solution, which I deemed too convoluted. As it often happens, the low-level stuff got pretty convoluted itself. I have worked a bit with Dapper which seems to be a middle-ground, in that you have strings, but can avoid embedded column/table strings. It takes a lot of the guessing out, but does not add any compatibility magic. I recently wrote something similar to Linq2db, which I think is a nice way work with databases. It is important that we can "go back to text", if we need to run one of the queries that are not supported. I am in favor of converting some of the more complex queries to Linq2db, and see if it works as expected. If it works, well we can consider eventually converting all the queries, and measure if there is any performance impacts. |
As part of the Issues clean up effort to make bugs fewer and more visible, I'm giving this an |
Hello there!
I'd like to ask everyone involved in a project on opinion.
IMO, code that deals with local db operations is less than ideal in respect to maintainability and overall readability. Those huge string literals with SQLite commands and low level DB class usage is something that could improved on. How about switching to something like FluentMigrator and Linq2Db (specific tools to use are up for debate, of course, used these as an example).
I'd like to at least try to implement this, but I want to listen for a feedback first.
Will it sit right with core dev team? Is this something that could make dealing with duplicati code easier for everyone and not just myself?
This switch could make optimizing backup operations easier and make possible integration with server DBMS as well (although, this is not final goal of this proposal). Not to mention that this won't hurt possible future migration to .net 5, if this ever arise.
So, what do you think?
The text was updated successfully, but these errors were encountered: