You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
uptime-kuma/server/utils/knex/lib/dialects/mysql2/schema/mysql2-columncompiler.js

23 lines
1.1 KiB

1 month ago
const ColumnCompilerMySQL = require("knex/lib/dialects/mysql/schema/mysql-columncompiler");
1 month ago
const { formatDefault } = require("knex/lib/formatter/formatterUtils");
const { log } = require("../../../../../../../src/util");
1 month ago
class KumaColumnCompiler extends ColumnCompilerMySQL {
/**
1 month ago
* Override defaultTo method to handle default value for TEXT fields
1 month ago
* @param {any} value Value
* @returns {string|void} Default value (Don't understand why it can return void or string, but it's the original code, lol)
*/
defaultTo(value) {
1 month ago
if (this.type === "text" && typeof value === "string") {
log.debug("defaultTo", `${this.args[0]}: ${this.type} ${value} ${typeof value}`);
// MySQL 8.0 is required and only if the value is written as an expression: https://dev.mysql.com/doc/refman/8.0/en/data-type-defaults.html
1 month ago
// MariaDB 10.2 is required: https://mariadb.com/kb/en/text/
1 month ago
return `default (${formatDefault(value, this.type, this.client)})`;
1 month ago
}
1 month ago
return super.defaultTo.apply(this, arguments);
1 month ago
}
}
module.exports = KumaColumnCompiler;