2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +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,17 +23,22 @@ class sqliteDatabase {
} }
async migrate() { async migrate() {
let commit = false;
for (let doctype in frappe.modules) { for (let doctype in frappe.modules) {
// check if controller module // check if controller module
if (frappe.modules[doctype].Meta) { if (frappe.modules[doctype].Meta) {
if (await this.table_exists(doctype)) { if (await this.table_exists(doctype)) {
await this.alter_table(doctype); await this.alter_table(doctype);
commit = true
} else { } else {
await this.create_table(doctype); await this.create_table(doctype);
commit = true
} }
} }
} }
if ( commit )
await this.commit(); await this.commit();
} }
@ -45,9 +50,9 @@ class sqliteDatabase {
for (let df of meta.get_valid_fields({ with_children: false })) { for (let df of meta.get_valid_fields({ with_children: false })) {
if (this.type_map[df.fieldtype]) { if (this.type_map[df.fieldtype]) {
columns.push(this.get_column_definition(df)); columns.push(this.get_column_definition(df));
if (df.default) { // if (df.default) {
values.push(df.default); // values.push(df.default);
} // }
} }
} }
@ -62,7 +67,7 @@ class sqliteDatabase {
} }
get_column_definition(df) { 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) { async alter_table(doctype) {