As a way of extending the support for data migration I have added some code #995
Replies: 8 comments 40 replies
-
BTW, I am not suggesting that we drop all the tables on every execution of each of our applications. Only when there have been changes that are not updated (because sync_schema cannot detect a change for instance) or in cases where sync_schema would drop and loose data (see my Guide, data migration)... |
Beta Was this translation helpful? Give feedback.
-
I would like to upload the code files of the above mentioned extensions... what is the best way to do this? |
Beta Was this translation helpful? Give feedback.
-
Actually there can be a schema where one cannot detect a strict sort order of tables cause table A can have a FK to table B and reverse simultaneously. Example: table |
Beta Was this translation helpful? Give feedback.
-
Sqlite studio uses pragma foreign_keys 0 before dropping and creating tables and then resets it to 1
This is the reason why I think we should have access to this pragma
Sync_schema would be run by shutting down foreign_keys to 0 doing the work, and then resetting to 1
Actually foreign_keys should be 0 when we start dropping tables and reset to 1 after all data is reloaded
This should be done with RAII IDIOM to ensure the pragma is reset!
That is the way one can create the schema in a SQL client but can also be created within the full data migration using sync_schema
Cheers 🍻
Juan
…Sent from my iPhone
s to thi1
On 1 Apr 2022, at 10:02 PM, 1should Zakharov ***@***.***> wrote:
Actually there can be a schema where one cannot detect a strict sort order of tables cause table A can have a FK to table B and reverse simultaneously. Example: table books has a FK to category storing book's category and table category can has FK to books with the latest added book of this category. Such a schema can be created using external SQLite client, cannot be created using sync_schema but can be supported by sqlite_orm. Developer may want to alter such a schema with sqlite_orm. How would you do this?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.
|
Beta Was this translation helpful? Give feedback.
-
Since all inserting/updating is done with PRAGMA FOREIGN_KEY 1, we know the DB is in a valid referential integrity state before the sync_schema(), then turn off PRAGMA FOREIGN KEY, load the tables, drop them, reset the schema and reinsert the tables, resetting FOREIGN_KEY to 1 |
Beta Was this translation helpful? Give feedback.
-
It is necessary to disable foreign_key checking else the insert will not work in the general case where the row with the reportsto FK is not inserted before the current row!! |
Beta Was this translation helpful? Give feedback.
-
@juandent please check out |
Beta Was this translation helpful? Give feedback.
-
Let's concentrate on advanced migrations API. It will solve both cyclic FKs problem and FK enabled/disabled problem |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The order in which tables can be dropped is subject to certain restrictions: tables with dependent rows cannot be dropped.
To be able to drop tables with the certainty that we will drop them in correct order, we need an algorithm that "sorts" the types. I have implemented this algorithm. The idea is to use it like this:
This behavior works like a stack and it would be nice to create a vector of vectors but how since each table represents a different type - so vec0 may be something like
std::vector<Album>
and vec1 something likestd::vector<Artist>
, etc, clearly impossible to create a stack of vectors... if there is a way to make this more generic please let me know... I don't like to hang my trust to the naming of the vectors (i.e. vec0, vec1,...). If there is a way please let me know!I am using the CRTP to define a general Database template class which has a couple of extension points:
which is common for all projects. A concrete class for each storage schema then follows:
the name tuple_derived should be replaced by something more appropriate - it is a temporary name. The implementation of the ordering algorithm is as follows (this needs to be called for every pair of types that require some order between them):
I would like to know what you think about this...
I will prepare .h files to package this physically. I suppose I can then upload the files for your review.
Thanks in advance,
Juan Dent
Beta Was this translation helpful? Give feedback.
All reactions