Skip to content

Commit

Permalink
fix(MariaDBVariable): Remove bool option
Browse files Browse the repository at this point in the history
Does not work correctly with ansible's mysql_variables module
"ON" and "OFF" work fine

- Make innodb_print_all_deadlocks str, not bool
  • Loading branch information
balamurali27 committed Jul 3, 2024
1 parent 0244df0 commit 9731dc5
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 98 deletions.
158 changes: 79 additions & 79 deletions press/fixtures/mariadb_variable.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,181 +132,181 @@
"skippable": 0
},
{
"datatype": "Str",
"default_value": "",
"doc_section": "replication-and-binary-log",
"datatype": "Int",
"default_value": "5120",
"doc_section": "server",
"docstatus": 0,
"doctype": "MariaDB Variable",
"dynamic": 1,
"modified": "2023-08-03 14:20:47.702196",
"name": "expire_logs_days",
"set_on_new_servers": 0,
"modified": "2023-09-22 08:38:16.807229",
"name": "tmp_disk_table_size",
"set_on_new_servers": 1,
"skippable": 0
},
{
"datatype": "Str",
"default_value": "37",
"doc_section": "innodb",
"docstatus": 0,
"doctype": "MariaDB Variable",
"dynamic": 1,
"modified": "2023-09-15 15:21:13.086214",
"name": "innodb_old_blocks_pct",
"set_on_new_servers": 0,
"skippable": 0
},
{
"datatype": "Int",
"default_value": null,
"doc_section": "innodb",
"default_value": "5",
"doc_section": "server",
"docstatus": 0,
"doctype": "MariaDB Variable",
"dynamic": 1,
"modified": "2023-06-15 14:41:36.038646",
"name": "innodb_buffer_pool_size",
"set_on_new_servers": 0,
"modified": "2024-03-05 12:55:47.689706",
"name": "extra_max_connections",
"set_on_new_servers": 1,
"skippable": 0
},
{
"datatype": "Str",
"default_value": "/var/lib/mysql/mysql-bin",
"doc_section": "replication-and-binary-log",
"default_value": "3307",
"doc_section": "server",
"docstatus": 0,
"doctype": "MariaDB Variable",
"dynamic": 0,
"modified": "2023-06-15 14:41:09.156699",
"name": "log_bin",
"set_on_new_servers": 0,
"skippable": 1
"modified": "2024-03-05 12:55:54.950776",
"name": "extra_port",
"set_on_new_servers": 1,
"skippable": 0
},
{
"datatype": "Str",
"default_value": "5000",
"doc_section": "innodb",
"default_value": "100",
"doc_section": "server",
"docstatus": 0,
"doctype": "MariaDB Variable",
"dynamic": 1,
"modified": "2023-09-22 14:02:04.157025",
"name": "innodb_old_blocks_time",
"modified": "2023-12-17 20:05:35.338733",
"name": "max_connections",
"set_on_new_servers": 1,
"skippable": 0
},
{
"datatype": "Int",
"default_value": "512",
"datatype": "Str",
"default_value": null,
"doc_section": "server",
"docstatus": 0,
"doctype": "MariaDB Variable",
"dynamic": 1,
"modified": "2023-09-22 08:38:25.704420",
"name": "max_allowed_packet",
"set_on_new_servers": 1,
"modified": "2024-01-12 14:21:03.949888",
"name": "max_user_connections",
"set_on_new_servers": 0,
"skippable": 0
},
{
"datatype": "Int",
"default_value": "5120",
"doc_section": "server",
"datatype": "Str",
"default_value": null,
"doc_section": "replication-and-binary-log",
"docstatus": 0,
"doctype": "MariaDB Variable",
"dynamic": 1,
"modified": "2023-09-22 08:38:16.807229",
"name": "tmp_disk_table_size",
"set_on_new_servers": 1,
"modified": "2024-03-05 12:59:31.069472",
"name": "binlog_expire_logs_seconds",
"set_on_new_servers": 0,
"skippable": 0
},
{
"datatype": "Str",
"default_value": "5",
"datatype": "Int",
"default_value": "32",
"doc_section": "server",
"docstatus": 0,
"doctype": "MariaDB Variable",
"dynamic": 1,
"modified": "2024-03-05 12:55:47.689706",
"name": "extra_max_connections",
"set_on_new_servers": 1,
"modified": "2024-06-12 10:30:47.403256",
"name": "max_heap_table_size",
"set_on_new_servers": 0,
"skippable": 0
},
{
"datatype": "Str",
"default_value": "3307",
"doc_section": "server",
"default_value": "",
"doc_section": "replication-and-binary-log",
"docstatus": 0,
"doctype": "MariaDB Variable",
"dynamic": 0,
"modified": "2024-03-05 12:55:54.950776",
"name": "extra_port",
"set_on_new_servers": 1,
"dynamic": 1,
"modified": "2023-08-03 14:20:47.702196",
"name": "expire_logs_days",
"set_on_new_servers": 0,
"skippable": 0
},
{
"datatype": "Str",
"default_value": "100",
"doc_section": "server",
"default_value": "37",
"doc_section": "innodb",
"docstatus": 0,
"doctype": "MariaDB Variable",
"dynamic": 1,
"modified": "2023-12-17 20:05:35.338733",
"name": "max_connections",
"set_on_new_servers": 1,
"modified": "2023-09-15 15:21:13.086214",
"name": "innodb_old_blocks_pct",
"set_on_new_servers": 0,
"skippable": 0
},
{
"datatype": "Str",
"datatype": "Int",
"default_value": null,
"doc_section": "server",
"doc_section": "innodb",
"docstatus": 0,
"doctype": "MariaDB Variable",
"dynamic": 1,
"modified": "2024-01-12 14:21:03.949888",
"name": "max_user_connections",
"modified": "2023-06-15 14:41:36.038646",
"name": "innodb_buffer_pool_size",
"set_on_new_servers": 0,
"skippable": 0
},
{
"datatype": "Str",
"default_value": null,
"default_value": "/var/lib/mysql/mysql-bin",
"doc_section": "replication-and-binary-log",
"docstatus": 0,
"doctype": "MariaDB Variable",
"dynamic": 1,
"modified": "2024-03-05 12:59:31.069472",
"name": "binlog_expire_logs_seconds",
"dynamic": 0,
"modified": "2023-06-15 14:41:09.156699",
"name": "log_bin",
"set_on_new_servers": 0,
"skippable": 0
"skippable": 1
},
{
"datatype": "Str",
"default_value": "3600",
"doc_section": "server",
"default_value": "5000",
"doc_section": "innodb",
"docstatus": 0,
"doctype": "MariaDB Variable",
"dynamic": 1,
"modified": "2024-03-28 15:23:30.635417",
"name": "max_statement_time",
"modified": "2023-09-22 14:02:04.157025",
"name": "innodb_old_blocks_time",
"set_on_new_servers": 1,
"skippable": 0
},
{
"datatype": "Int",
"default_value": "32",
"default_value": "512",
"doc_section": "server",
"docstatus": 0,
"doctype": "MariaDB Variable",
"dynamic": 1,
"modified": "2024-06-12 10:30:47.403256",
"name": "max_heap_table_size",
"set_on_new_servers": 0,
"modified": "2023-09-22 08:38:25.704420",
"name": "max_allowed_packet",
"set_on_new_servers": 1,
"skippable": 0
},
{
"datatype": "Bool",
"datatype": "Str",
"default_value": "3600",
"doc_section": "server",
"docstatus": 0,
"doctype": "MariaDB Variable",
"dynamic": 1,
"modified": "2024-03-28 15:23:30.635417",
"name": "max_statement_time",
"set_on_new_servers": 1,
"skippable": 0
},
{
"datatype": "Str",
"default_value": null,
"doc_section": "innodb",
"docstatus": 0,
"doctype": "MariaDB Variable",
"dynamic": 1,
"modified": "2024-07-02 19:20:23.150723",
"modified": "2024-07-03 07:13:23.014958",
"name": "innodb_print_all_deadlocks",
"set_on_new_servers": 0,
"skippable": 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"mariadb_variable",
"value_int",
"value_str",
"value_bool",
"value_float",
"skip",
"persist"
Expand Down Expand Up @@ -41,12 +40,6 @@
"in_list_view": 1,
"label": "Skip"
},
{
"default": "0",
"fieldname": "value_bool",
"fieldtype": "Check",
"label": "Value Bool"
},
{
"default": "0",
"fieldname": "persist",
Expand All @@ -64,7 +57,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-06-01 10:55:14.041364",
"modified": "2024-07-03 07:15:03.695917",
"modified_by": "Administrator",
"module": "Press",
"name": "Database Server MariaDB Variable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class DatabaseServerMariaDBVariable(Document):
parenttype: DF.Data
persist: DF.Check
skip: DF.Check
value_bool: DF.Check
value_float: DF.Float
value_int: DF.Int
value_str: DF.Data | None
Expand All @@ -36,11 +35,11 @@ def datatype(self) -> str:
return frappe.db.get_value("MariaDB Variable", self.mariadb_variable, "datatype")

@property
def value_fields(self):
def value_fields(self) -> list[str]:
return list(filter(lambda x: x.startswith("value_"), self.as_dict().keys()))

@property
def value_field(self):
def value_field(self) -> str:
"""Return the first value field that has a value"""
for f in self.value_fields:
if self.get(f):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_only_one_datatype_value_can_be_set_for_one_mariadb_variable(self):
{
"mariadb_variable": "innodb_buffer_pool_size",
"value_int": 1000,
"value_bool": True,
"value_str": str(1000 * 1024),
},
)
with self.assertRaises(frappe.ValidationError):
Expand All @@ -63,7 +63,7 @@ def test_value_field_set_matches_datatype(self):
"mariadb_system_variables",
{
"mariadb_variable": "innodb_buffer_pool_size",
"value_bool": 1000, # seeing if only value is checked and not the field
"value_str": "1000", # seeing if only value is checked and not the field
},
)
with self.assertRaises(frappe.ValidationError):
Expand All @@ -79,7 +79,7 @@ def test_value_field_set_matches_datatype(self):
server.save()

def test_only_skippable_variables_can_be_skipped(self):
"""Test that only bool variables can be skipped"""
"""Test that only skippable variables can be skipped"""
server = create_test_database_server()
server.append(
"mariadb_system_variables",
Expand Down
4 changes: 2 additions & 2 deletions press/press/doctype/mariadb_variable/mariadb_variable.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"fieldname": "datatype",
"fieldtype": "Select",
"label": "Datatype",
"options": "Int\nBool\nFloat\nStr",
"options": "Int\nFloat\nStr",
"reqd": 1
},
{
Expand Down Expand Up @@ -65,7 +65,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-09-22 08:36:43.526135",
"modified": "2024-07-03 07:14:39.263413",
"modified_by": "Administrator",
"module": "Press",
"name": "MariaDB Variable",
Expand Down
4 changes: 1 addition & 3 deletions press/press/doctype/mariadb_variable/mariadb_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MariaDBVariable(Document):
if TYPE_CHECKING:
from frappe.types import DF

datatype: DF.Literal["Int", "Bool", "Float", "Str"]
datatype: DF.Literal["Int", "Float", "Str"]
default_value: DF.Data | None
doc_section: DF.Literal["server", "replication-and-binary-log", "innodb"]
dynamic: DF.Check
Expand All @@ -32,8 +32,6 @@ def get_default_value(self):
return int(value)
case "Float":
return float(value)
case "Bool":
return bool(value)
return value

@frappe.whitelist()
Expand Down

0 comments on commit 9731dc5

Please sign in to comment.