1from __future__ import annotations
2
3import sys
4from typing import Any
5
6from plain.models.backends.base.creation import BaseDatabaseCreation
7
8
9class DatabaseCreation(BaseDatabaseCreation):
10 def sql_table_creation_suffix(self) -> str:
11 suffix = []
12 test_settings = self.connection.settings_dict["TEST"]
13 if test_settings["CHARSET"]:
14 suffix.append("CHARACTER SET {}".format(test_settings["CHARSET"]))
15 if test_settings["COLLATION"]:
16 suffix.append("COLLATE {}".format(test_settings["COLLATION"]))
17 return " ".join(suffix)
18
19 def _execute_create_test_db(self, cursor: Any, parameters: dict[str, Any]) -> None:
20 try:
21 super()._execute_create_test_db(cursor, parameters)
22 except Exception as e:
23 if len(e.args) < 1 or e.args[0] != 1007:
24 # All errors except "database exists" (1007) cancel tests.
25 self.log(f"Got an error creating the test database: {e}")
26 sys.exit(2)
27 else:
28 raise