Add option to change type of single column, adjust README

This commit is contained in:
Akumatic 2023-05-04 11:47:38 +02:00
parent 2673c92b4e
commit d243bdf77c
2 changed files with 8 additions and 3 deletions

View File

@ -15,7 +15,7 @@ If an error occurs during the conversion of a table or column, an output with th
## Usage ## Usage
``` ```
python convert.py [-h] [-v] -H HOST -P PORT -u USER -p PASSWORD -d DATABASE python convert.py [-h] [-v] [-s] -H HOST -P PORT -u USER -p PASSWORD -d DATABASE
``` ```
Required arguments: Required arguments:
- `-H/--host HOST` - `-H/--host HOST`
@ -27,4 +27,4 @@ Required arguments:
Optional arguments: Optional arguments:
- `-h/--help` - `-h/--help`
- `-v/--verbose` - `-v/--verbose`
- `-s/--statistics`

View File

@ -253,6 +253,7 @@ 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
) -> None: ) -> None:
@ -264,6 +265,10 @@ class UTF8MB4Converter:
- a dict containig information about the column to be altered - a dict containig information about the column to be altered
- table (str) - table (str)
- the table housing the column - the table housing the column
- newtype (str)
- enter a new type if it should be changed
- if no type is entered, the type is kept
- default value: None
- charset (str) - charset (str)
- target character set - target character set
- default value: utf8mb4 - default value: utf8mb4
@ -287,7 +292,7 @@ class UTF8MB4Converter:
query = " ".join(( query = " ".join((
f"ALTER TABLE {table} CHANGE {col} {col}", f"ALTER TABLE {table} CHANGE {col} {col}",
f"{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']}" "NULL" if column["nullable"] == "YES" else f"NOT NULL DEFAULT {column['dvalue']}"
)) ))
try: try: