diff --git a/migra/command.py b/migra/command.py index 99af4a1..066e0a4 100644 --- a/migra/command.py +++ b/migra/command.py @@ -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.",