Add --supported
arg for rattail mysql-chars
flag
to show what the underlying DB engine supports this also enables "live mode" which will actually attempt to modify live DB / tables...fingers crossed
This commit is contained in:
parent
ad4f882c2e
commit
18f7b8a43f
1 changed files with 29 additions and 4 deletions
|
@ -68,6 +68,10 @@ class MysqlChars(Subcommand):
|
||||||
"not specified, all info will be shown for the "
|
"not specified, all info will be shown for the "
|
||||||
"object(s) regardless of their charset/collation.")
|
"object(s) regardless of their charset/collation.")
|
||||||
|
|
||||||
|
parser.add_argument('--supported', action='store_true',
|
||||||
|
help="Instead of showing current DB/table info, show "
|
||||||
|
"what's actually supported by underlying DB engine.")
|
||||||
|
|
||||||
parser.add_argument('--fix', action='store_true',
|
parser.add_argument('--fix', action='store_true',
|
||||||
help="Execute SQL to convert charset and/or collation "
|
help="Execute SQL to convert charset and/or collation "
|
||||||
"for relevant objects. Note, this will affect \"all\" "
|
"for relevant objects. Note, this will affect \"all\" "
|
||||||
|
@ -102,11 +106,32 @@ class MysqlChars(Subcommand):
|
||||||
engine.dialect.name, engine))
|
engine.dialect.name, engine))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if args.fix:
|
if args.supported:
|
||||||
|
self.view_supported(engine)
|
||||||
|
elif args.fix:
|
||||||
self.fix_db(engine, args)
|
self.fix_db(engine, args)
|
||||||
else:
|
else:
|
||||||
self.view_db(engine, args)
|
self.view_db(engine, args)
|
||||||
|
|
||||||
|
def view_supported(self, engine):
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
COLLATIONS = sa.sql.table(
|
||||||
|
'COLLATIONS',
|
||||||
|
sa.sql.column('COLLATION_NAME'),
|
||||||
|
sa.sql.column('CHARACTER_SET_NAME'),
|
||||||
|
sa.sql.column('IS_DEFAULT'),
|
||||||
|
schema='information_schema')
|
||||||
|
|
||||||
|
query = sa.sql.select(COLLATIONS.c.COLLATION_NAME,
|
||||||
|
COLLATIONS.c.CHARACTER_SET_NAME,
|
||||||
|
COLLATIONS.c.IS_DEFAULT)\
|
||||||
|
.order_by(COLLATIONS.c.COLLATION_NAME)
|
||||||
|
|
||||||
|
with engine.begin() as cxn:
|
||||||
|
result = cxn.execute(query)
|
||||||
|
self.show_results(result.fetchall())
|
||||||
|
|
||||||
def view_db(self, engine, args):
|
def view_db(self, engine, args):
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
@ -170,7 +195,7 @@ class MysqlChars(Subcommand):
|
||||||
self.stdout.write("\n")
|
self.stdout.write("\n")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
engine.execute(stmt)
|
||||||
|
|
||||||
tablesinfo = self.fetch_tablesinfo(engine, args,
|
tablesinfo = self.fetch_tablesinfo(engine, args,
|
||||||
offenders_only=args.offenders)
|
offenders_only=args.offenders)
|
||||||
|
@ -193,7 +218,7 @@ class MysqlChars(Subcommand):
|
||||||
compile_kwargs={'literal_binds': True})))
|
compile_kwargs={'literal_binds': True})))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
engine.execute(stmt)
|
||||||
|
|
||||||
if args.dry_run:
|
if args.dry_run:
|
||||||
self.stdout.write("\n")
|
self.stdout.write("\n")
|
||||||
|
@ -232,7 +257,7 @@ class MysqlChars(Subcommand):
|
||||||
compile_kwargs={'literal_binds': True})))
|
compile_kwargs={'literal_binds': True})))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
engine.execute(stmt)
|
||||||
|
|
||||||
if args.dry_run and printed_header:
|
if args.dry_run and printed_header:
|
||||||
self.stdout.write("\n")
|
self.stdout.write("\n")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue