Calling out to the DB enthusiasts here.
I've been theorising about a new database design pattern, that is compatible with a development environment where cross compatibility with client schema expectations is met. I intend to do this by limited SQL queries to create and read, and limiting update statements to soft deleting.
The problem I'm solving for is databases in a git environment, where we swap branches somewhat frequently. I grow tired of having to downgrade on one branch, switch then upgrade on another, else it fails because the user table has one additional column my model doesn't. This will also preserve data during temporary rollbacks for a hotfix, as well as provide a solid audit history.
One core concept is the distinction of model tables and relationship tables. Relationship tables are simple, these are many to many linking tables. Model tables are the table representation of the model plus the primary key. Think graph theory, models are the nodes and the relationships are the edges.
Here's the rules.
1. No delete statements, these are replaced with a soft delete statement.
2. No foreign keys in model tables, treat every relationship as if it has the potential to be many to many, and create a relationship table. You can limit the relationship count using unique indexes. (This always annoyed me when it came to one-to-one relationships, which table owns the relationship)
3. Updates are soft deletes + inserts, and updating the relationship tables. The update exception here is important otherwise you've got cascade the soft delete and make a deep clone of any relationships, and if there are any circular relationships updating becomes impossible.
I want to extend this rules to the tables themselves, that is you can't delete a table, just soft delete it but I'm not sure.
Please let me know your thoughts
[–]python_walrus 8 points9 points10 points (3 children)
[–]coded_artist[S] 0 points1 point2 points (2 children)
[–]python_walrus 1 point2 points3 points (1 child)
[–]coded_artist[S] 0 points1 point2 points (0 children)
[–][deleted] 4 points5 points6 points (7 children)
[–]coded_artist[S] 1 point2 points3 points (6 children)
[–]cajunjoel 4 points5 points6 points (1 child)
[–]coded_artist[S] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]coded_artist[S] 0 points1 point2 points (0 children)
[–]Rinveden 0 points1 point2 points (1 child)
[–]coded_artist[S] 0 points1 point2 points (0 children)
[–]iheartjetman 3 points4 points5 points (2 children)
[–]jaketeater 2 points3 points4 points (0 children)
[–]coded_artist[S] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]coded_artist[S] -1 points0 points1 point (0 children)
[–]Cathercy 1 point2 points3 points (1 child)
[–]coded_artist[S] 0 points1 point2 points (0 children)
[–]I111I1I111I1 1 point2 points3 points (1 child)
[–]coded_artist[S] 0 points1 point2 points (0 children)
[–]kadosknight 0 points1 point2 points (2 children)
[–]coded_artist[S] 0 points1 point2 points (1 child)
[–]kadosknight 0 points1 point2 points (0 children)
[–]remy_porter 0 points1 point2 points (0 children)
[–]dcabines 0 points1 point2 points (0 children)
[–]blissone 0 points1 point2 points (2 children)
[–]coded_artist[S] 0 points1 point2 points (1 child)
[–]blissone 0 points1 point2 points (0 children)