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