Advertisement
chadjoan

Draft pseudocode for database differencing

Apr 1st, 2024
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 KB | None | 0 0
  1. conn = new SQLConnection();
  2.  
  3. make_vcs_db_query = file_read(\Kickback\SCRIPT_ROOT . "/../meta/schema/kickback-kingdom-schema.mysql");
  4.  
  5. // Replace the schema name: `kickbackdb` -> `kickbackdb_vcs`
  6. // (Ideally, we'd do this in a more syntax-aware way.
  7. // Perhaps we could get mysqldump to parameterize the database name?
  8. // Then we could parameterize the query instead of using fragile hacky regex stuff.)
  9. make_vcs_db_query ~= s/\bkickbackdb\b/kickbackdb_vcs/g;
  10.  
  11. // Create the `kickbackdb_vcs` database.
  12. conn.execute(make_vcs_db_query);
  13.  
  14. // Query that finds tables that exist in local database (kickbackdb) but not in VCS database (kickbackdb_vcs).
  15. results = conn.execute("...");
  16. diff.add_to_tables_removed(results);
  17.  
  18. // Query that finds tables that exist in VCS database (kickbackdb_vcs) but not in local database (kickbackdb).
  19. results = conn.execute("...");
  20. diff.add_to_tables_added(results);
  21.  
  22. // Query that finds tables that exist in BOTH databases.
  23. table_list = conn.execute("...");
  24. foreach( table in table_list )
  25. {
  26.   // Query that finds columns that exist in the local table, but not in the VCS table.
  27.   results = conn.execute("...");
  28.   diff.add_to_columns_removed(table, results);
  29.  
  30.   // Query that finds columns that exist in the VCS table, but not in the local table.
  31.   results = conn.execute("...");
  32.   diff.add_to_columns_added(table, results);
  33.  
  34.   // Query that finds keys that exist in the local table, but not in the VCS table.
  35.   results = conn.execute("...");
  36.   diff.add_to_keys_removed(table, results);
  37.  
  38.   // Query that finds keys that exist in the VCS table, but not in the local table.
  39.   results = conn.execute("...");
  40.   diff.add_to_keys_added(table, results);
  41.  
  42.   // ditto for any other table-level entities
  43.  
  44.   // Also you may want to diff for any data-level differences if the data
  45.   // is something semantically significant in code.
  46.   // (We should avoid semantically-signficant data as much as possible,
  47.   // though things like badges in the current site ARE this kind of thing.)
  48.   // So, like, adding a new badge type should probably appear in the diff.
  49. }
  50.  
  51. // ditto for things like triggers, views, etc
  52.  
  53. // Query that deletes kickbackdb_vcs
  54. conn.execute("...");
  55.  
  56. // Present the difference to the admin
  57. display_diff(diff);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement