• Like

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Database versioning

  • 3,156 views
Uploaded on

Describes how to givee MySQL databases the notion of time. Lets you roll back database tables to any point in time, consistently across tables and without affecting other users.

Describes how to givee MySQL databases the notion of time. Lets you roll back database tables to any point in time, consistently across tables and without affecting other users.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
3,156
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
25
Comments
0
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Johan Sölve @macsolve http://re.solve.se
  • 2. Relational databases • Two dimensional • Rows and columns • Only know about NOW • Has no concept of ”history”
  • 3. What if we can add a third dimension?
  • 4. What if we can add the notion of TIME
  • 5. Data Versioning
  • 6. Data Versioning • ”Time Machine” for data • Snapshot of any point in time • Immediately and continously available • No rollback or restore of database • Demo: http://johan.solve.se/dataversioning/
  • 7. Data Versioning • Consistent across tables • Solution for MySQL • Uses VIEW to access data • Data access it transparent to the application • Unique for each database session/ visitor
  • 8. Views • Views are like search macros • They are created as a saved SELECT statement • Performs good if indexed properly
  • 9. Data Versioning • Eachmaintains every version of each that table is replaced by a ”data” table row/record • Common ”version” table • Points at current row in data table • Keeps meta data about changes • Each table is completed by a VIEW to
  • 10. Never Change • Most important: • Never update or delete a row in the data table • All changes add a new row in the data table
  • 11. Time Table Row 1 Row 2 Row 3 Row 4 Row 5
  • 12. Time Table Row 1 Row 2 Row 3 Row 4 Row 5 Table 2 Row 1 Row 2 Row 3 Row 4
  • 13. Database operations – CRUD • SELECT from a view - just as usual • INSERT table a row in data table and verison creates • UPDATE updates creates a rowininthe version table and a timestamp the data table and version table • DELETEtable a timestamp in the version updates
  • 14. Database operations – CRUD • SELECT – no change • INSERT, UPDATE, DELETE handles specially • Triggers and Stored procedures • Or in the application’s database abstraction layer
  • 15. INSERT INSERT INTO version (guid, changedby_start) VALUES ("gweyufghkj", "JS"); INSERT INTO people_data (id_version, firstname, lastname) VALUES (LAST_INSERT_ID(), "Nisse", "Hult");
  • 16. UPDATE UPDATE version SET changedby_end="JS", dt_end=NOW() WHERE guid="gweyufghkj" AND dt_end="3000-01-01 00:00:00"; INSERT INTO version (guid, changedby_start) VALUES ("gweyufghkj", "JS");
  • 17. DELETE UPDATE version SET changedby_end="JS", dt_end=NOW() WHERE guid="gweyufghkj" AND dt_end="3000-01-01 00:00:00";
  • 18. SELECT SELECT * FROM people;
  • 19. View CREATE VIEW people AS SELECT people_data.*, version.guid FROM people_data JOIN version ON people_data.id_version=version.id WHERE dt_start <= history() AND dt_end > history();
  • 20. Go Back in Time SET @history="2010-02-22 10:00:00"; SELECT * FROM people; Only affects this database session
  • 21. Uses • Content Management • Definitions for dynamic forms • Data entryatmust point inform definition any match time
  • 22. Considerations • Carefullyto includeforin datatable if it’s relevant evaluate it each versioning Example: • Permission settings • What if the table structure changes? • Performance • Consider using emulated
  • 23. Implementation • Modified knop_database • Methods for: -> addrecord -> saverecord -> deleterecord
  • 24. Read more • Description: http://re.solve.se/database-versioning • Demo: http://johan.solve.se/dataversioning/ Johan Sölve