Commit 42789ecb authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Turn boolean fields into BOOLEAN data type.

Add conversion to change JavaScript booleans into 0 and 1 for MySQL.
parent a7c9594d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ CREATE TABLE comments (
    content TEXT NOT NULL,
    content_html TEXT NOT NULL,
    created_at DATETIME NOT NULL,
    deleted ENUM('Y', 'N') NOT NULL DEFAULT 'N',
    deleted BOOLEAN NOT NULL DEFAULT 0,
    FOREIGN KEY (user_id) REFERENCES users (id),
    FOREIGN KEY (target_id) REFERENCES targets (id)
);
@@ -15,7 +15,7 @@ CREATE TABLE users (
    username VARCHAR(255) NOT NULL,
    external_id INT NOT NULL, -- (link to Sencha Forum database)
    email VARCHAR(255) NOT NULL, -- (from subscriptions)
    moderator ENUM('Y', 'N') NOT NULL DEFAULT 'N'
    moderator BOOLEAN NOT NULL DEFAULT 0
);

CREATE TABLE targets (
+11 −2
Original line number Diff line number Diff line
@@ -293,7 +293,7 @@ var CommentsTable = (function() {
                content: c.content,
                content_html: c.contentHtml,
                created_at: c.createdAt,
                deleted: c.deleted
                deleted: !!c.deleted
            };
        });
        return map;
@@ -454,13 +454,22 @@ function asyncPrint(msg) {

function printInserts(table) {
    return function(data, next) {
        data[table].forEach(function(row) {
        data[table].map(fixBooleans).forEach(function(row) {
            console.log(db.format("INSERT INTO "+table+" SET ?;", row));
        });
        next();
    };
}

// turn true and false into 0 and 1 for MySQL insertion
function fixBooleans(row) {
    for (var i in row) {
        if (row[i] === true || row[i] === false) {
            row[i] = row[i] ? 1 : 0;
        }
    }
    return row;
}


sequence({}, [