2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 03:29:00 +00:00

Fix Default Value cases

This commit is contained in:
Achilles Rasquinha 2018-02-01 14:54:28 +05:30
parent 0327667e2c
commit dac410dd0b

View File

@ -23,18 +23,23 @@ class sqliteDatabase {
}
async migrate() {
let commit = false;
for (let doctype in frappe.modules) {
// check if controller module
if (frappe.modules[doctype].Meta) {
if (await this.table_exists(doctype)) {
await this.alter_table(doctype);
commit = true
} else {
await this.create_table(doctype);
commit = true
}
}
}
await this.commit();
if ( commit )
await this.commit();
}
async create_table(doctype) {
@ -45,9 +50,9 @@ class sqliteDatabase {
for (let df of meta.get_valid_fields({ with_children: false })) {
if (this.type_map[df.fieldtype]) {
columns.push(this.get_column_definition(df));
if (df.default) {
values.push(df.default);
}
// if (df.default) {
// values.push(df.default);
// }
}
}
@ -62,7 +67,7 @@ class sqliteDatabase {
}
get_column_definition(df) {
return `${df.fieldname} ${this.type_map[df.fieldtype]} ${df.reqd && !df.default ? "not null" : ""} ${df.default ? "default ?" : ""}`
return `${df.fieldname} ${this.type_map[df.fieldtype]} ${df.reqd && !df.default ? "not null" : ""} ${df.default ? `default ${df.default}` : ""}`
}
async alter_table(doctype) {