Change order of function calls, fix conversion of columns
This commit is contained in:
@ -32,8 +32,8 @@ def main (
|
|||||||
logging.getLogger("Main").info(f"Database statistics:\n{stats}")
|
logging.getLogger("Main").info(f"Database statistics:\n{stats}")
|
||||||
else:
|
else:
|
||||||
db.convert_charset_db()
|
db.convert_charset_db()
|
||||||
db.convert_charset_all_tables()
|
|
||||||
db.convert_charset_all_columns_all_tables()
|
db.convert_charset_all_columns_all_tables()
|
||||||
|
db.convert_charset_all_tables()
|
||||||
|
|
||||||
def parse_args (
|
def parse_args (
|
||||||
) -> argparse.Namespace:
|
) -> argparse.Namespace:
|
||||||
|
@ -253,9 +253,9 @@ class UTF8MB4Converter:
|
|||||||
self,
|
self,
|
||||||
column: dict,
|
column: dict,
|
||||||
table: str,
|
table: str,
|
||||||
newtype: str = None,
|
|
||||||
charset: str = DEFAULT_CHARSET,
|
charset: str = DEFAULT_CHARSET,
|
||||||
collation: str = DEFAULT_COLLATION
|
collation: str = DEFAULT_COLLATION,
|
||||||
|
newtype: str = None
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Alters the charset and collation of a single column.
|
Alters the charset and collation of a single column.
|
||||||
@ -283,17 +283,21 @@ class UTF8MB4Converter:
|
|||||||
if not column["charset"]:
|
if not column["charset"]:
|
||||||
self.logger.debug(f"Column {col}(@{table}) has no default character set")
|
self.logger.debug(f"Column {col}(@{table}) has no default character set")
|
||||||
return
|
return
|
||||||
if not column["type"] in ["char", "varchar", "text", "longtext"]:
|
|
||||||
self.logger.debug(f"Column {col}(@{table}) does contain data of type {column['type']}")
|
|
||||||
return
|
|
||||||
if column["charset"] == charset:
|
if column["charset"] == charset:
|
||||||
self.logger.debug(f"Column {col}(@{table}) already has character set {charset}")
|
self.logger.debug(f"Column {col}(@{table}) already has character set {charset}")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if column['nullable'] == "YES":
|
||||||
|
constraint = "NULL"
|
||||||
|
else:
|
||||||
|
constraint = "NOT NULL"
|
||||||
|
if column['dvalue'] is not None:
|
||||||
|
constraint += f" DEFAULT {column['dvalue']}"
|
||||||
|
|
||||||
query = " ".join((
|
query = " ".join((
|
||||||
f"ALTER TABLE {table} CHANGE {col} {col}",
|
f"ALTER TABLE {table} CHANGE {col} {col}",
|
||||||
f"{newtype or column['ctype']} CHARACTER SET {charset} COLLATE {collation}",
|
f"{newtype or column['ctype']} CHARACTER SET {charset} COLLATE {collation}",
|
||||||
"NULL" if column["nullable"] == "YES" else f"NOT NULL DEFAULT {column['dvalue']}"
|
constraint
|
||||||
))
|
))
|
||||||
try:
|
try:
|
||||||
self.cur.execute(query)
|
self.cur.execute(query)
|
||||||
|
Reference in New Issue
Block a user