Commit b92d27f5 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Change all DATETIME fields into TIMESTAMP.

This way we can take advantage of automatic updating of the created_at
fields and don't need to insert new Date() into all of those columns.
parent b663d234
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -223,8 +223,7 @@ Comments.prototype = {
                target_id: target_id,
                user_id: comment.user_id,
                content: comment.content,
                content_html: Formatter.format(comment.content),
                created_at: new Date()
                content_html: Formatter.format(comment.content)
            }, callback);
        }.bind(this));
    },
@@ -253,8 +252,7 @@ Comments.prototype = {
            this.db.insert("updates", {
                comment_id: comment.id,
                user_id: comment.user_id,
                action: 'update',
                created_at: new Date()
                action: 'update'
            }, callback);
        }.bind(this));
    },
@@ -282,8 +280,7 @@ Comments.prototype = {
            this.db.insert("updates", {
                comment_id: action.id,
                user_id: action.user_id,
                action: action.deleted ? 'delete' : 'undo_delete',
                created_at: new Date()
                action: action.deleted ? 'delete' : 'undo_delete'
            }, callback);
        }.bind(this));
    },
@@ -315,7 +312,6 @@ Comments.prototype = {
    },

    castVote: function(vote, callback) {
        vote.created_at = new Date();
        this.db.insert("votes", vote, function(err, vote_id) {
            if (err) {
                // vote already exists, retrieve it
@@ -354,7 +350,6 @@ Comments.prototype = {
     * @param {Error} callback.err
     */
    markRead: function(read, callback) {
        read.created_at = new Date();
        this.db.insert("readings", read, function(err) {
            if (err && err.code === "ER_DUP_ENTRY") {
                callback();
+1 −2
Original line number Diff line number Diff line
@@ -68,8 +68,7 @@ Subscriptions.prototype = {
            this.targets.ensure(subscription.target, function(err, target_id) {
                this.db.insert("subscriptions", {
                    user_id: subscription.user_id,
                    target_id: target_id,
                    created_at: new Date()
                    target_id: target_id
                }, callback);
            }.bind(this));
        }.bind(this));
+5 −5
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ CREATE TABLE comments (
    content TEXT NOT NULL,
    content_html TEXT NOT NULL,
    vote INT NOT NULL DEFAULT 0,
    created_at DATETIME NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    deleted BOOLEAN NOT NULL DEFAULT 0,
    FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
    FOREIGN KEY (target_id) REFERENCES targets (id) ON DELETE CASCADE
@@ -34,7 +34,7 @@ CREATE TABLE votes (
    user_id INT NOT NULL,
    comment_id INT NOT NULL,
    value INT NOT NULL, -- +1 or -1
    created_at DATETIME NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
    FOREIGN KEY (comment_id) REFERENCES comments (id) ON DELETE CASCADE,
    -- can't vote twice on the same comment
@@ -46,7 +46,7 @@ CREATE TABLE updates (
    user_id INT NOT NULL,
    comment_id INT NOT NULL,
    action ENUM('update', 'delete') DEFAULT 'update',
    created_at DATETIME NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
    FOREIGN KEY (comment_id) REFERENCES comments (id) ON DELETE CASCADE
) ENGINE = InnoDB, CHARACTER SET = utf8;
@@ -55,7 +55,7 @@ CREATE TABLE subscriptions (
    id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    target_id INT NOT NULL,
    created_at DATETIME NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
    FOREIGN KEY (target_id) REFERENCES targets (id) ON DELETE CASCADE,
    -- can't subscribe twice to the same thread
@@ -66,7 +66,7 @@ CREATE TABLE readings (
    id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    comment_id INT NOT NULL,
    created_at DATETIME NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
    FOREIGN KEY (comment_id) REFERENCES comments (id) ON DELETE CASCADE,
    -- can't read the same comment twice