def migrate(conn, tables):
    import os
    from systools import sys_log_debug
    updateTablesPriority = ["Users"]

    sys_log_debug("[migrate] start")
    for table in updateTablesPriority:
        if tables["Users"]:
            sys_log_debug("[migrate] table {}".format(table))
            strCommonFields = ", ".join(tables[table]["fields_Common"])
            sys_log_debug("[migrate] copying data for table {}".format(table))
            if "NfcUuid" not in tables[table]["fields_Common"]:
                newFields = strCommonFields + ", NfcUuid"
                oldFields = strCommonFields + ", Password"
                stmt = "INSERT OR REPLACE INTO %s (%s) SELECT %s FROM old.%s;" % (table, newFields, oldFields, table)
            else:
                stmt = "INSERT OR REPLACE INTO %s (%s) SELECT %s FROM old.%s;" % (table, strCommonFields, strCommonFields, table)
            conn.query(stmt)
            sys_log_debug("[migrate] finished query for table {}".format(table))
        else:
            sys_log_debug("[migrate] table {}".format(table))
            strCommonFields = ", ".join(tables[table]["fields_Common"])
            sys_log_debug("[migrate] copying data for table {}".format(table))
            stmt = "INSERT OR REPLACE INTO %s (%s) SELECT %s FROM old.%s;" % (table, strCommonFields, strCommonFields, table)
            conn.query(stmt)
            sys_log_debug("[migrate] finished query for table {}".format(table))

    sys_log_debug("[migrate] finished iterating")
