added a command argument --encode-utf8 to address the issue #13 and pull #50

This commit is contained in:
Mohammad M. Shahbazi 2018-10-15 07:10:23 +03:30
parent 83727fa36b
commit 0c6145174e

View File

@ -47,6 +47,13 @@ def parse_args(args):
default=False,
help="Also output privilege differences (ie. grant/revoke statements)",
)
parser.add_argument(
"--encode-utf8",
dest="encode_utf8",
action="store_true",
default=False,
help="Use UTF-8 encoding for output",
)
parser.add_argument("dburl_from", help="The database you want to migrate.")
parser.add_argument(
"dburl_target", help="The database you want to use as the target."
@ -70,7 +77,10 @@ def run(args, out=None, err=None):
m.add_all_changes(privileges=args.with_privileges)
try:
if m.statements:
print(m.sql.encode('utf8'), file=out)
if args.encode_utf8:
print(m.sql.encode('utf8'), file=out)
else:
print(m.sql, file=out)
except UnsafeMigrationException:
print(
"-- ERROR: destructive statements generated. Use the --unsafe flag to suppress this error.",