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.
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
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";
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