Your SlideShare is downloading. ×
Database versioning
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Database versioning

3,268
views

Published 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.


0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,268
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
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. DataVersioning
  • 6. DataVersioning • ”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. DataVersioning • Consistent across tables • Solution for MySQL • UsesVIEW 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. DataVersioning • Each table is replaced by a ”data” table that maintains every version of each row/record • Common ”version” table • Points at current row in data table • Keeps meta data about changes • Each table is completed by aVIEW 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 Row 1 Row 2 Row 3 Row 4 Row 5 Table
  • 12. Time Row 1 Row 2 Row 3 Row 4 Row 5 Table Table 2 Row 1 Row 2 Row 3 Row 4
  • 13. Database operations – CRUD • SELECT from a view - just as usual • INSERT creates a row in data table and verison table • UPDATE updates a timestamp in the version table and creates a row in the data table and version table • DELETE updates a timestamp in the version table
  • 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 CREATEVIEW 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 entry must match form definition at any point in time
  • 22. Considerations • Carefully evaluate for each table if it’s relevant to include it in data 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