Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly set UpdateTime to update to current time on a change to the row #28

Merged
merged 4 commits into from Feb 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions schemas/cloud.sql
Expand Up @@ -2,7 +2,7 @@
-- CloudRecords

CREATE TABLE CloudRecords (
UpdateTime TIMESTAMP,
UpdateTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

VMUUID VARCHAR(255) NOT NULL,
SiteID INT NOT NULL, -- Foreign key
Expand Down Expand Up @@ -87,7 +87,7 @@ DELIMITER ;

DROP TABLE IF EXISTS CloudSummaries;
CREATE TABLE CloudSummaries (
UpdateTime TIMESTAMP,
UpdateTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

SiteID INT NOT NULL, -- Foreign key

Expand Down Expand Up @@ -253,7 +253,7 @@ DELIMITER ;
-- LastUpdated
DROP TABLE IF EXISTS LastUpdated;
CREATE TABLE LastUpdated (
UpdateTime TIMESTAMP NOT NULL,
UpdateTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
Type VARCHAR(255) PRIMARY KEY
);

Expand Down
13 changes: 13 additions & 0 deletions scripts/update_schema.sql
@@ -0,0 +1,13 @@
-- This script will set any null UpdateTimes to now
-- and then explicitly set the UpdateTimes of
-- future rows to update

UPDATE CloudRecords SET UpdateTime = CURRENT_TIMESTAMP WHERE UpdateTime IS NULL;
ALTER TABLE CloudRecords MODIFY COLUMN UpdateTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

UPDATE CloudSummaries SET UpdateTime = CURRENT_TIMESTAMP WHERE UpdateTime IS NULL;
ALTER TABLE CloudSummaries MODIFY COLUMN UpdateTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

UPDATE LastUpdated SET UpdateTime = CURRENT_TIMESTAMP WHERE UpdateTime IS NULL;
ALTER TABLE LastUpdated MODIFY COLUMN UpdateTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;