@@ -51,7 +51,7 @@ CREATE TABLE `tabDocField` ( | |||||
KEY `label` (`label`), | KEY `label` (`label`), | ||||
KEY `fieldtype` (`fieldtype`), | KEY `fieldtype` (`fieldtype`), | ||||
KEY `fieldname` (`fieldname`) | KEY `fieldname` (`fieldname`) | ||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | |||||
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | |||||
-- | -- | ||||
@@ -89,7 +89,7 @@ CREATE TABLE `tabDocPerm` ( | |||||
`restrict` int(1) DEFAULT NULL, | `restrict` int(1) DEFAULT NULL, | ||||
PRIMARY KEY (`name`), | PRIMARY KEY (`name`), | ||||
KEY `parent` (`parent`) | KEY `parent` (`parent`) | ||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | |||||
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | |||||
-- | -- | ||||
-- Table structure for table `tabDocType` | -- Table structure for table `tabDocType` | ||||
@@ -151,7 +151,7 @@ CREATE TABLE `tabDocType` ( | |||||
`custom` int(1) DEFAULT NULL, | `custom` int(1) DEFAULT NULL, | ||||
PRIMARY KEY (`name`), | PRIMARY KEY (`name`), | ||||
KEY `parent` (`parent`) | KEY `parent` (`parent`) | ||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | |||||
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | |||||
-- | -- | ||||
-- Table structure for table `tabSeries` | -- Table structure for table `tabSeries` | ||||
@@ -161,7 +161,7 @@ DROP TABLE IF EXISTS `tabSeries`; | |||||
CREATE TABLE `tabSeries` ( | CREATE TABLE `tabSeries` ( | ||||
`name` varchar(100) DEFAULT NULL, | `name` varchar(100) DEFAULT NULL, | ||||
`current` int(10) DEFAULT NULL | `current` int(10) DEFAULT NULL | ||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | |||||
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | |||||
-- | -- | ||||
@@ -177,7 +177,7 @@ CREATE TABLE `tabSessions` ( | |||||
`lastupdate` datetime(6) DEFAULT NULL, | `lastupdate` datetime(6) DEFAULT NULL, | ||||
`status` varchar(20) DEFAULT NULL, | `status` varchar(20) DEFAULT NULL, | ||||
KEY `sid` (`sid`) | KEY `sid` (`sid`) | ||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | |||||
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | |||||
-- | -- | ||||
@@ -190,7 +190,7 @@ CREATE TABLE `tabSingles` ( | |||||
`field` varchar(255) DEFAULT NULL, | `field` varchar(255) DEFAULT NULL, | ||||
`value` text, | `value` text, | ||||
KEY `singles_doctype_field_index` (`doctype`, `field`) | KEY `singles_doctype_field_index` (`doctype`, `field`) | ||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | |||||
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | |||||
-- | -- | ||||
-- Table structure for table `__Auth` | -- Table structure for table `__Auth` | ||||
@@ -201,7 +201,7 @@ CREATE TABLE `__Auth` ( | |||||
`user` VARCHAR(255) NOT NULL PRIMARY KEY, | `user` VARCHAR(255) NOT NULL PRIMARY KEY, | ||||
`password` VARCHAR(255) NOT NULL, | `password` VARCHAR(255) NOT NULL, | ||||
KEY `user` (`user`) | KEY `user` (`user`) | ||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | |||||
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | |||||
-- | -- | ||||
-- Table structure for table `tabFile Data` | -- Table structure for table `tabFile Data` | ||||
@@ -229,7 +229,7 @@ CREATE TABLE `tabFile Data` ( | |||||
KEY `parent` (`parent`), | KEY `parent` (`parent`), | ||||
KEY `attached_to_name` (`attached_to_name`), | KEY `attached_to_name` (`attached_to_name`), | ||||
KEY `attached_to_doctype` (`attached_to_doctype`) | KEY `attached_to_doctype` (`attached_to_doctype`) | ||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | |||||
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | |||||
-- | -- | ||||
-- Table structure for table `tabDefaultValue` | -- Table structure for table `tabDefaultValue` | ||||
@@ -252,4 +252,4 @@ CREATE TABLE `tabDefaultValue` ( | |||||
PRIMARY KEY (`name`), | PRIMARY KEY (`name`), | ||||
KEY `parent` (`parent`), | KEY `parent` (`parent`), | ||||
KEY `defaultvalue_parent_defkey_index` (`parent`,`defkey`) | KEY `defaultvalue_parent_defkey_index` (`parent`,`defkey`) | ||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | |||||
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; |
@@ -7,13 +7,14 @@ import frappe | |||||
import json | import json | ||||
no_value_fields = ['Section Break', 'Column Break', 'HTML', 'Table', 'Button', 'Image', 'Fold', 'Heading'] | |||||
display_fieldtypes = ['Section Break', 'Column Break', 'HTML', 'Button', 'Image', 'Fold', 'Heading'] | |||||
default_fields = ['doctype','name','owner','creation','modified','modified_by', | |||||
'parent','parentfield','parenttype','idx','docstatus'] | |||||
integer_docfield_properties = ["reqd", "search_index", "in_list_view", "permlevel", | |||||
no_value_fields = ('Section Break', 'Column Break', 'HTML', 'Table', 'Button', 'Image', 'Fold', 'Heading') | |||||
display_fieldtypes = ('Section Break', 'Column Break', 'HTML', 'Button', 'Image', 'Fold', 'Heading') | |||||
default_fields = ('doctype','name','owner','creation','modified','modified_by', | |||||
'parent','parentfield','parenttype','idx','docstatus') | |||||
integer_docfield_properties = ("reqd", "search_index", "in_list_view", "permlevel", | |||||
"hidden", "read_only", "ignore_user_permissions", "allow_on_submit", "report_hide", | "hidden", "read_only", "ignore_user_permissions", "allow_on_submit", "report_hide", | ||||
"in_filter", "no_copy", "print_hide", "unique"] | |||||
"in_filter", "no_copy", "print_hide", "unique") | |||||
optional_fields = ("_user_tags", "_comments", "_assign", "_starred_by") | |||||
def rename(doctype, old, new, debug=False): | def rename(doctype, old, new, debug=False): | ||||
import frappe.model.rename_doc | import frappe.model.rename_doc | ||||
@@ -10,6 +10,7 @@ import frappe.share | |||||
import frappe.permissions | import frappe.permissions | ||||
from frappe.utils import flt, cint, getdate, get_datetime, get_time | from frappe.utils import flt, cint, getdate, get_datetime, get_time | ||||
from frappe import _ | from frappe import _ | ||||
from frappe.model import optional_fields | |||||
class DatabaseQuery(object): | class DatabaseQuery(object): | ||||
def __init__(self, doctype): | def __init__(self, doctype): | ||||
@@ -161,7 +162,7 @@ class DatabaseQuery(object): | |||||
# remove from fields | # remove from fields | ||||
to_remove = [] | to_remove = [] | ||||
for fld in self.fields: | for fld in self.fields: | ||||
for f in ("_user_tags", "_comments", "_assign", "_starred_by"): | |||||
for f in optional_fields: | |||||
if f in fld and not f in columns: | if f in fld and not f in columns: | ||||
to_remove.append(fld) | to_remove.append(fld) | ||||
@@ -175,7 +176,7 @@ class DatabaseQuery(object): | |||||
each = [each] | each = [each] | ||||
for element in each: | for element in each: | ||||
if element in ("_user_tags", "_comments", "_assign", "_starred_by") and element not in columns: | |||||
if element in optional_fields and element not in columns: | |||||
to_remove.append(each) | to_remove.append(each) | ||||
for each in to_remove: | for each in to_remove: | ||||
@@ -112,7 +112,9 @@ class DbTable: | |||||
idx int(8), | idx int(8), | ||||
%sindex parent(parent)) | %sindex parent(parent)) | ||||
ENGINE=InnoDB | ENGINE=InnoDB | ||||
CHARACTER SET=utf8""" % (self.name, add_text)) | |||||
ROW_FORMAT=COMPRESSED | |||||
CHARACTER SET=utf8mb4 | |||||
COLLATE=utf8mb4_unicode_ci""" % (self.name, add_text)) | |||||
def get_column_definitions(self): | def get_column_definitions(self): | ||||
column_list = [] + default_columns | column_list = [] + default_columns | ||||
@@ -6,7 +6,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import frappe, json | import frappe, json | ||||
from frappe.utils import cstr, cint | from frappe.utils import cstr, cint | ||||
from frappe.model import integer_docfield_properties, default_fields | |||||
from frappe.model import integer_docfield_properties, default_fields, no_value_fields, optional_fields | |||||
from frappe.model.document import Document | from frappe.model.document import Document | ||||
from frappe.model.base_document import BaseDocument | from frappe.model.base_document import BaseDocument | ||||
from frappe.model.db_schema import type_map | from frappe.model.db_schema import type_map | ||||
@@ -41,7 +41,7 @@ def load_doctype_from_file(doctype): | |||||
class Meta(Document): | class Meta(Document): | ||||
_metaclass = True | _metaclass = True | ||||
default_fields = default_fields[1:] | |||||
default_fields = list(default_fields)[1:] | |||||
special_doctypes = ("DocField", "DocPerm", "Role", "DocType", "Module Def") | special_doctypes = ("DocField", "DocPerm", "Role", "DocType", "Module Def") | ||||
def __init__(self, doctype): | def __init__(self, doctype): | ||||
@@ -322,3 +322,18 @@ def get_default_df(fieldname): | |||||
fieldname = fieldname, | fieldname = fieldname, | ||||
fieldtype = "Data" | fieldtype = "Data" | ||||
) | ) | ||||
def trim_tables(): | |||||
"""Use this to remove columns that don't exist in meta""" | |||||
ignore_fields = default_fields + optional_fields | |||||
for doctype in frappe.db.get_all("DocType", filters={"issingle": 0}): | |||||
doctype = doctype.name | |||||
columns = frappe.db.get_table_columns(doctype) | |||||
fields = [df.fieldname for df in frappe.get_meta(doctype).fields if df.fieldtype not in no_value_fields] | |||||
columns_to_remove = [f for f in list(set(columns) - set(fields)) if f not in ignore_fields] | |||||
if columns_to_remove: | |||||
columns_to_remove = ", ".join(["drop `{0}`".format(c) for c in columns_to_remove]) | |||||
query = """alter table `tab{doctype}` {columns}""".format( | |||||
doctype=doctype, columns=columns_to_remove) | |||||
frappe.db.sql_ddl(query) |
@@ -1,4 +1,5 @@ | |||||
execute:frappe.db.sql("""update `tabPatch Log` set patch=replace(patch, '.4_0.', '.v4_0.')""") #2014-05-12 | execute:frappe.db.sql("""update `tabPatch Log` set patch=replace(patch, '.4_0.', '.v4_0.')""") #2014-05-12 | ||||
frappe.patches.v5_0.convert_to_barracuda_and_utf8mb4 | |||||
execute:frappe.reload_doc('core', 'doctype', 'doctype', force=True) #2014-01-24 | execute:frappe.reload_doc('core', 'doctype', 'doctype', force=True) #2014-01-24 | ||||
execute:frappe.reload_doc('core', 'doctype', 'docfield', force=True) #2015-01-01 | execute:frappe.reload_doc('core', 'doctype', 'docfield', force=True) #2015-01-01 | ||||
execute:frappe.reload_doc('core', 'doctype', 'docperm') #2014-06-04 | execute:frappe.reload_doc('core', 'doctype', 'docperm') #2014-06-04 | ||||
@@ -68,3 +69,4 @@ frappe.patches.v5_0.bookmarks_to_stars | |||||
frappe.patches.v5_0.style_settings_to_website_theme | frappe.patches.v5_0.style_settings_to_website_theme | ||||
frappe.patches.v5_0.rename_ref_type_fieldnames | frappe.patches.v5_0.rename_ref_type_fieldnames | ||||
frappe.patches.v5_0.fix_email_alert | frappe.patches.v5_0.fix_email_alert | ||||
@@ -0,0 +1,41 @@ | |||||
from __future__ import unicode_literals | |||||
import frappe | |||||
import sys | |||||
def execute(): | |||||
check_if_ready_for_barracuda() | |||||
for table in frappe.db.get_tables(): | |||||
frappe.db.sql_ddl("""alter table `{0}` ENGINE=InnoDB ROW_FORMAT=COMPRESSED""".format(table)) | |||||
frappe.db.sql_ddl("""alter table `{0}` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci""".format(table)) | |||||
def check_if_ready_for_barracuda(): | |||||
mariadb_variables = frappe._dict(frappe.db.sql("""show variables""")) | |||||
for key, value in { | |||||
"innodb_file_format": "Barracuda", | |||||
"innodb_file_per_table": "ON", | |||||
"innodb_large_prefix": "ON", | |||||
"character_set_server": "utf8mb4", | |||||
"collation_server": "utf8mb4_unicode_ci" | |||||
}.items(): | |||||
if mariadb_variables.get(key) != value: | |||||
print "="*80 | |||||
print "Please add this to MariaDB's my.cnf and restart MariaDB before proceeding" | |||||
print expected | |||||
print "="*80 | |||||
sys.exit(1) | |||||
# raise Exception, "MariaDB needs to be configured!" | |||||
expected = """[mysqld] | |||||
innodb-file-format=barracuda | |||||
innodb-file-per-table=1 | |||||
innodb-large-prefix=1 | |||||
character-set-client-handshake = FALSE | |||||
character-set-server = utf8mb4 | |||||
collation-server = utf8mb4_unicode_ci | |||||
[mysql] | |||||
default-character-set = utf8mb4 | |||||
""" |